Class: Lurch::Changeset
- Inherits:
-
Object
- Object
- Lurch::Changeset
- Defined in:
- lib/lurch/changeset.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#relationships ⇒ Object
Returns the value of attribute relationships.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, attributes = {}) ⇒ Changeset
constructor
A new instance of Changeset.
- #inspect ⇒ Object
- #set(key, value) ⇒ Object
- #set_related(relationship_key, related_resources) ⇒ Object
Constructor Details
#initialize(type, attributes = {}) ⇒ Changeset
Returns a new instance of Changeset.
6 7 8 9 10 11 12 |
# File 'lib/lurch/changeset.rb', line 6 def initialize(type, attributes = {}) is_resource = type.is_a?(Resource) @type = is_resource ? type.type : Inflector.decode_type(type) @id = is_resource ? type.id : nil @attributes = attributes @relationships = {} end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/lurch/changeset.rb', line 4 def attributes @attributes end |
#errors ⇒ Object
Returns the value of attribute errors.
4 5 6 |
# File 'lib/lurch/changeset.rb', line 4 def errors @errors end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/lurch/changeset.rb', line 3 def id @id end |
#relationships ⇒ Object
Returns the value of attribute relationships.
4 5 6 |
# File 'lib/lurch/changeset.rb', line 4 def relationships @relationships end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/lurch/changeset.rb', line 3 def type @type end |
Instance Method Details
#inspect ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/lurch/changeset.rb', line 24 def inspect attrs = ["id: #{id.inspect}"] attrs = attrs.concat(attributes.map { |name, value| "#{name}: #{value.inspect}" }) attrs = attrs.concat(relationships.map { |name, value| "#{name}: #{value.inspect}" }) inspection = attrs.join(", ") "#<#{self.class}[#{Inflector.classify(type)}] #{inspection}>" end |
#set(key, value) ⇒ Object
14 15 16 17 |
# File 'lib/lurch/changeset.rb', line 14 def set(key, value) attributes[key.to_sym] = value self end |
#set_related(relationship_key, related_resources) ⇒ Object
19 20 21 22 |
# File 'lib/lurch/changeset.rb', line 19 def (relationship_key, ) @relationships[relationship_key.to_sym] = self end |