Class: Meteor::AttributeMap
- Inherits:
-
Object
- Object
- Meteor::AttributeMap
- Defined in:
- lib/meteor/attribute_map.rb
Overview
Attribute Map Class (属性マップ クラス)
Instance Attribute Summary collapse
-
#map ⇒ Object
Returns the value of attribute map.
-
#recordable ⇒ Object
Returns the value of attribute recordable.
Instance Method Summary collapse
-
#[](name) ⇒ String
get attribute value using attribute name (属性名で属性値を取得する).
-
#[]=(name, value) ⇒ Object
set a couple of attribute name and attribute value (属性名と属性値を対としてセットする).
-
#changed(name) ⇒ true, false
get update flag of attribute using attribute name (属性名で属性の変更フラグを取得する).
-
#delete(name) ⇒ Object
delete attribute using attribute name (属性名に対応した属性を削除する).
-
#fetch(name) ⇒ String
get attribute value using attribute name (属性名で属性値を取得する).
-
#initialize(*args) ⇒ AttributeMap
constructor
initializer (イニシャライザ).
-
#names ⇒ Array
get attribute name array (属性名配列を取得する).
-
#removed(name) ⇒ true, false
get delete flag of attribute using attribute name (属性名で属性の削除状況を取得する).
-
#store(name, value) ⇒ Object
set a couple of attribute name and attribute value (属性名と属性値を対としてセットする).
Constructor Details
#initialize ⇒ AttributeMap #initialize(attr_map) ⇒ AttributeMap
initializer (イニシャライザ)
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/meteor/attribute_map.rb', line 15 def initialize(*args) case args.length when ZERO initialize_0 when ONE initialize_1(args[0]) else raise ArgumentError end end |
Instance Attribute Details
#map ⇒ Object
Returns the value of attribute map.
123 124 125 |
# File 'lib/meteor/attribute_map.rb', line 123 def map @map end |
#recordable ⇒ Object
Returns the value of attribute recordable.
124 125 126 |
# File 'lib/meteor/attribute_map.rb', line 124 def recordable @recordable end |
Instance Method Details
#[](name) ⇒ String
get attribute value using attribute name (属性名で属性値を取得する)
142 143 144 |
# File 'lib/meteor/attribute_map.rb', line 142 def [](name) fetch(name) end |
#[]=(name, value) ⇒ Object
set a couple of attribute name and attribute value (属性名と属性値を対としてセットする)
132 133 134 |
# File 'lib/meteor/attribute_map.rb', line 132 def []=(name, value) store(name, value) end |
#changed(name) ⇒ true, false
get update flag of attribute using attribute name (属性名で属性の変更フラグを取得する)
107 108 109 110 111 |
# File 'lib/meteor/attribute_map.rb', line 107 def changed(name) if @map[name] @map[name].changed end end |
#delete(name) ⇒ Object
delete attribute using attribute name (属性名に対応した属性を削除する)
96 97 98 99 100 101 |
# File 'lib/meteor/attribute_map.rb', line 96 def delete(name) if @recordable && @map[name] @map[name].removed = true @map[name].changed = false end end |
#fetch(name) ⇒ String
get attribute value using attribute name (属性名で属性値を取得する)
86 87 88 89 90 |
# File 'lib/meteor/attribute_map.rb', line 86 def fetch(name) if @map[name] && !@map[name].removed @map[name].value end end |
#names ⇒ Array
get attribute name array (属性名配列を取得する)
77 78 79 |
# File 'lib/meteor/attribute_map.rb', line 77 def names @map.keys end |
#removed(name) ⇒ true, false
get delete flag of attribute using attribute name (属性名で属性の削除状況を取得する)
117 118 119 120 121 |
# File 'lib/meteor/attribute_map.rb', line 117 def removed(name) if @map[name] @map[name].removed end end |
#store(name, value) ⇒ Object
set a couple of attribute name and attribute value (属性名と属性値を対としてセットする)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/meteor/attribute_map.rb', line 53 def store(name, value) if !@map[name] attr = Attribute.new attr.name = name attr.value = value if @recordable attr.changed = true attr.removed = false end @map[name] = attr else attr = @map[name] if @recordable && attr.value != value attr.changed = true attr.removed = false end attr.value = value end end |