Module: ActiveGraph::Shared::Attributes
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::AttributeMethods
- Included in:
- TypecastedAttributes
- Defined in:
- lib/active_graph/shared/attributes.rb
Overview
Attributes provides a set of class methods for defining an attributes schema and instance methods for reading and writing attributes.
Originally part of ActiveAttr, github.com/cgriego/active_attr
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- DEPRECATED_OBJECT_METHODS =
Methods deprecated on the Object class which can be safely overridden
%w(id type)
- ATTRIBUTES_METHOD_PATTERNS =
Gem::Requirement.create('>= 7.1').satisfied_by?(Gem.loaded_specs["activesupport"].version) ? :attribute_method_patterns : :attribute_method_matchers
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Performs equality checking on the result of attributes and its type.
-
#attributes ⇒ Hash{String => Object}
Returns a Hash of all attributes.
- #query_attribute(name) ⇒ Object
-
#write_attribute(name, value) ⇒ Object
(also: #[]=)
Write a single attribute to the model’s attribute hash.
Instance Method Details
#==(other) ⇒ true, false
Performs equality checking on the result of attributes and its type.
38 39 40 41 |
# File 'lib/active_graph/shared/attributes.rb', line 38 def ==(other) return false unless other.instance_of? self.class attributes == other.attributes end |
#attributes ⇒ Hash{String => Object}
Returns a Hash of all attributes
49 50 51 |
# File 'lib/active_graph/shared/attributes.rb', line 49 def attributes attributes_map { |name| send name } end |
#query_attribute(name) ⇒ Object
71 72 73 74 75 |
# File 'lib/active_graph/shared/attributes.rb', line 71 def query_attribute(name) fail ActiveGraph::UnknownAttributeError, "unknown attribute: #{name}" if !respond_to? "#{name}?" send "#{name}?" end |
#write_attribute(name, value) ⇒ Object Also known as: []=
Write a single attribute to the model’s attribute hash.
64 65 66 67 68 |
# File 'lib/active_graph/shared/attributes.rb', line 64 def write_attribute(name, value) fail ActiveGraph::UnknownAttributeError, "unknown attribute: #{name}" if !respond_to? "#{name}=" send "#{name}=", value end |