Class: Arrest::Attribute
- Inherits:
-
Object
- Object
- Arrest::Attribute
- Defined in:
- lib/arrest/attributes/attribute.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#clazz ⇒ Object
Returns the value of attribute clazz.
-
#dirty ⇒ Object
Returns the value of attribute dirty.
-
#json_name ⇒ Object
Returns the value of attribute json_name.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #dirty? ⇒ Boolean
- #from_hash(parent, value) ⇒ Object
-
#initialize(name, clazz, actions = nil) ⇒ Attribute
constructor
A new instance of Attribute.
- #mutable? ⇒ Boolean
- #read_only? ⇒ Boolean
- #to_hash(value) ⇒ Object
Constructor Details
#initialize(name, clazz, actions = nil) ⇒ Attribute
Returns a new instance of Attribute.
14 15 16 17 18 19 20 21 |
# File 'lib/arrest/attributes/attribute.rb', line 14 def initialize(name, clazz, actions = nil) @name = name.to_sym @actions = actions || [:create, :retrieve, :update, :delete] @clazz = clazz @dirty_sensitive = @clazz.ancestors.include?(Dirty) @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 |
#clazz ⇒ Object
Returns the value of attribute clazz.
12 13 14 |
# File 'lib/arrest/attributes/attribute.rb', line 12 def clazz @clazz 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
#dirty? ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/arrest/attributes/attribute.rb', line 31 def dirty? if @dirty_sensitive @dirty else true # treat as 'always' dirty end end |
#from_hash(parent, value) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/arrest/attributes/attribute.rb', line 39 def from_hash(parent, value) return if value == nil if @clazz.respond_to?(:convert) return @clazz.convert(value) end converter = CONVERTER[@clazz] if converter == nil puts "No converter for: #{@clazz.name}" converter = IdentConv end converter.convert value end |
#mutable? ⇒ Boolean
27 28 29 |
# File 'lib/arrest/attributes/attribute.rb', line 27 def mutable? @actions.include?(:create) || @actions.include?(:update) end |
#read_only? ⇒ Boolean
23 24 25 |
# File 'lib/arrest/attributes/attribute.rb', line 23 def read_only? @actions == [:retrieve] end |
#to_hash(value) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/arrest/attributes/attribute.rb', line 55 def to_hash value return nil unless value != nil if @clazz.respond_to?(:mk_json) return @clazz.mk_json(value) end converter = CONVERTER[@clazz] if converter == nil puts "No converter for: #{@clazz.name}" converter = IdentConv end converter.mk_json value end |