Module: Spyke::AttributeAssignment
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/spyke/attribute_assignment.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
95
96
97
98
99
100
101
102
103
|
# File 'lib/spyke/attribute_assignment.rb', line 95
def method_missing(name, *args, &block)
case
when association?(name) then association(name, *args).load
when attribute?(name) then attribute(name, *args)
when predicate?(name) then predicate(name, *args)
when setter?(name) then set_attribute(name, args.first)
else super
end
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
67
68
69
|
# File 'lib/spyke/attribute_assignment.rb', line 67
def ==(other)
other.instance_of?(self.class) && id? && id == other.id
end
|
#as_json(options = nil) ⇒ Object
76
77
78
|
# File 'lib/spyke/attribute_assignment.rb', line 76
def as_json(options = nil)
attributes.as_json(options)
end
|
#attributes ⇒ Object
42
43
44
|
# File 'lib/spyke/attribute_assignment.rb', line 42
def attributes
@spyke_attributes
end
|
#attributes=(new_attributes) ⇒ Object
46
47
48
49
|
# File 'lib/spyke/attribute_assignment.rb', line 46
def attributes=(new_attributes)
@spyke_attributes ||= Attributes.new(scope.params)
use_setters(new_attributes) if new_attributes
end
|
#hash ⇒ Object
63
64
65
|
# File 'lib/spyke/attribute_assignment.rb', line 63
def hash
id.hash
end
|
#id ⇒ Object
55
56
57
|
# File 'lib/spyke/attribute_assignment.rb', line 55
def id
attributes[primary_key]
end
|
#id=(value) ⇒ Object
59
60
61
|
# File 'lib/spyke/attribute_assignment.rb', line 59
def id=(value)
attributes[primary_key] = value if value.present?
end
|
#id? ⇒ Boolean
51
52
53
|
# File 'lib/spyke/attribute_assignment.rb', line 51
def id?
id.present?
end
|
#initialize(attributes = {}) {|_self| ... } ⇒ Object
36
37
38
39
40
|
# File 'lib/spyke/attribute_assignment.rb', line 36
def initialize(attributes = {})
self.attributes = attributes
@uri_template = scope.uri
yield self if block_given?
end
|
#inspect ⇒ Object
72
73
74
|
# File 'lib/spyke/attribute_assignment.rb', line 72
def inspect
"#<#{self.class}(#{@uri_template}) id: #{id.inspect} #{inspect_attributes}>"
end
|