Class: Arrest::Attribute
- Inherits:
-
Object
show all
- Defined in:
- lib/arrest/attributes/attribute.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, class_name, actions = nil) ⇒ Attribute
Returns a new instance of Attribute.
14
15
16
17
18
19
20
|
# File 'lib/arrest/attributes/attribute.rb', line 14
def initialize(name, class_name, actions = nil)
@name = name.to_sym
@actions = actions || [:create, :retrieve, :update, :delete]
@class_name = class_name.to_sym
@dirty = false
@json_name = Source.json_key_converter.key_to_json(name).to_sym
end
|
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
12
13
14
|
# File 'lib/arrest/attributes/attribute.rb', line 12
def actions
@actions
end
|
#dirty ⇒ Object
Returns the value of attribute dirty.
12
13
14
|
# File 'lib/arrest/attributes/attribute.rb', line 12
def dirty
@dirty
end
|
#json_name ⇒ Object
Returns the value of attribute json_name.
12
13
14
|
# File 'lib/arrest/attributes/attribute.rb', line 12
def json_name
@json_name
end
|
#name ⇒ Object
Returns the value of attribute name.
12
13
14
|
# File 'lib/arrest/attributes/attribute.rb', line 12
def name
@name
end
|
Instance Method Details
#clazz ⇒ Object
22
23
24
|
# File 'lib/arrest/attributes/attribute.rb', line 22
def clazz
@clazz ||= Arrest::Source.class_loader.load(@class_name)
end
|
#clazz=(c) ⇒ Object
26
27
28
|
# File 'lib/arrest/attributes/attribute.rb', line 26
def clazz=(c)
@clazz = c
end
|
42
43
44
45
46
47
48
|
# File 'lib/arrest/attributes/attribute.rb', line 42
def dirty?
if dirty_sensitive?
@dirty
else
true end
end
|
#dirty_sensitive? ⇒ Boolean
30
31
32
|
# File 'lib/arrest/attributes/attribute.rb', line 30
def dirty_sensitive?
@dirty_sensitive ||= clazz.ancestors.include?(Dirty)
end
|
#from_hash(parent, value) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/arrest/attributes/attribute.rb', line 50
def from_hash(parent, value)
return if value == nil
if self.clazz.respond_to?(:convert)
return self.clazz.convert(value)
end
converter = CONVERTER[self.clazz]
if converter == nil
puts "No converter for: #{self.clazz.name}"
converter = IdentConv
end
converter.convert value
end
|
38
39
40
|
# File 'lib/arrest/attributes/attribute.rb', line 38
def mutable?
@actions.include?(:create) || @actions.include?(:update)
end
|
34
35
36
|
# File 'lib/arrest/attributes/attribute.rb', line 34
def read_only?
@actions == [:retrieve]
end
|
#to_hash(value) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/arrest/attributes/attribute.rb', line 66
def to_hash value
return nil unless value != nil
if self.clazz.respond_to?(:mk_json)
return self.clazz.mk_json(value)
end
converter = CONVERTER[self.clazz]
if converter == nil
puts "No converter for: #{@self.clazz.name}"
converter = IdentConv
end
converter.mk_json value
end
|