Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/active_remote/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ module ClassMethods
def attribute_names
@attribute_names ||= attribute_types.keys
end

attr_reader :filtered_attribute_names

def filtered_attributes(attributes)
@filtered_attribute_names = attributes
end
end

def [](name)
Expand Down Expand Up @@ -45,7 +51,7 @@ def attribute_for_inspect(attr_name)
end

def attribute_names
@attributes.keys
@attributes.keys.delete(self.class.filtered_attribute_names) || []
end
end
end
2 changes: 1 addition & 1 deletion lib/active_remote/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def inspect
"not initialized"
end

"#<#{self.class} #{inspection}>"
"#<#{[self.class, inspection.presence].compact.join(' ')}>"
end

# Returns a hash of the given methods with their names as keys and returned values as values.
Expand Down
30 changes: 30 additions & 0 deletions spec/lib/active_remote/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,34 @@
described_class.new
end
end

describe "filtered_attributes" do
describe "single attribute" do
let(:subject) { ::User.new(:password => "foobar") }

it "#inspect doesn't show the password" do
expect(subject.inspect).not_to include("foobar")
end

it "#inspect just equals the class name" do
expect(subject.inspect).to eq("#<User>")
end
end

describe "multiple attributes" do
let(:subject) { ::Author.new(:name => "foo", :age => 15) }

it "#inspect doesn't show the name" do
expect(subject.inspect).not_to include("foo")
end

it "#inspect doesn't show the birthday" do
expect(subject.inspect).not_to include("15")
end

it "#inspect just equals the class name" do
expect(subject.inspect).to eq("#<Author>")
end
end
end
end
1 change: 1 addition & 0 deletions spec/support/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
require "support/models/no_attributes"
require "support/models/post"
require "support/models/tag"
require "support/models/user"
2 changes: 2 additions & 0 deletions spec/support/models/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Author < ::ActiveRemote::Base
attribute :writes_fiction, :boolean
attribute :net_sales, :float

filtered_attributes [:birthday, :age]

has_many :posts
has_many :user_posts, :class_name => "::Post", :scope => :user_guid
has_many :flagged_posts, :class_name => "::Post"
Expand Down
10 changes: 10 additions & 0 deletions spec/support/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "support/protobuf/post.pb"

##
# Define a generic class that inherits from active remote base
#
class User < ::ActiveRemote::Base
attribute :password, :string

filtered_attributes :password
end
32 changes: 32 additions & 0 deletions spec/support/protobuf/user.pb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# encoding: utf-8

##
# This file is auto-generated. DO NOT EDIT!
#
require 'protobuf'
require 'protobuf/rpc/service'


##
# Imports
#
require 'error.pb'

module Generic
module Remote
::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }

##
# Message Classes
#
class User < ::Protobuf::Message; end

##
# Message Fields
#
class User
optional :string, :password, 1
optional :string, :password_digest, 2
end
end
end