Module: ActiveRemote::Attributes
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::AttributeMethods
- Included in:
- Base
- Defined in:
- lib/active_remote/attributes.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#==(other) ⇒ Object
Performs equality checking on the result of attributes and its type.
-
#attribute(name) ⇒ Object
Read an attribute from the attributes hash.
-
#attribute=(name, value) ⇒ Object
Write an attribute to the attributes hash.
- #attribute_method?(attr_name) ⇒ Boolean
-
#attributes ⇒ Object
Returns a copy of our attributes hash.
-
#inspect ⇒ Object
Returns the class name plus its attributes.
-
#read_attribute(name) ⇒ Object
(also: #[])
Read attribute from the attributes hash.
-
#write_attribute(name, value) ⇒ Object
(also: #[]=)
Update an attribute in the attributes hash.
Instance Method Details
#==(other) ⇒ Object
Performs equality checking on the result of attributes and its type.
15 16 17 18 19 |
# File 'lib/active_remote/attributes.rb', line 15 def ==(other) return false unless other.instance_of?(self.class) attributes == other.attributes end |
#attribute(name) ⇒ Object
Read an attribute from the attributes hash
65 66 67 |
# File 'lib/active_remote/attributes.rb', line 65 def attribute(name) @attributes[name] end |
#attribute=(name, value) ⇒ Object
Write an attribute to the attributes hash
71 72 73 |
# File 'lib/active_remote/attributes.rb', line 71 def attribute=(name, value) @attributes[name] = self.class.attributes[name].from_user(value) end |
#attribute_method?(attr_name) ⇒ Boolean
75 76 77 78 79 |
# File 'lib/active_remote/attributes.rb', line 75 def attribute_method?(attr_name) # Check if @attributes is defined because dangerous_attribute? method # can check allocate.respond_to? before actaully calling initialize defined?(@attributes) && @attributes.key?(attr_name) end |
#attributes ⇒ Object
Returns a copy of our attributes hash
22 23 24 |
# File 'lib/active_remote/attributes.rb', line 22 def attributes @attributes.dup end |
#inspect ⇒ Object
Returns the class name plus its attributes
31 32 33 34 35 |
# File 'lib/active_remote/attributes.rb', line 31 def inspect attribute_descriptions = attributes.sort.map { |key, value| "#{key}: #{value.inspect}" }.join(", ") separator = " " unless attribute_descriptions.empty? "#<#{self.class.name}#{separator}#{attribute_descriptions}>" end |
#read_attribute(name) ⇒ Object Also known as: []
Read attribute from the attributes hash
39 40 41 42 43 44 45 46 47 |
# File 'lib/active_remote/attributes.rb', line 39 def read_attribute(name) name = name.to_s if respond_to?(name) attribute(name) else raise ::ActiveRemote::UnknownAttributeError, "unknown attribute: #{name}" end end |
#write_attribute(name, value) ⇒ Object Also known as: []=
Update an attribute in the attributes hash
52 53 54 55 56 57 58 59 60 |
# File 'lib/active_remote/attributes.rb', line 52 def write_attribute(name, value) name = name.to_s if respond_to?("#{name}=") __send__("attribute=", name, value) else raise ::ActiveRemote::UnknownAttributeError, "unknown attribute: #{name}" end end |