Class: Fog::Attributes::Default
- Inherits:
-
Object
- Object
- Fog::Attributes::Default
- Defined in:
- lib/fog/core/attributes/default.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#squash ⇒ Object
readonly
Returns the value of attribute squash.
Instance Method Summary collapse
- #create ⇒ Object
- #create_getter ⇒ Object
- #create_setter ⇒ Object
-
#initialize(model, name, options) ⇒ Default
constructor
A new instance of Default.
Constructor Details
#initialize(model, name, options) ⇒ Default
Returns a new instance of Default.
6 7 8 9 10 |
# File 'lib/fog/core/attributes/default.rb', line 6 def initialize(model, name, ) @model = model @name = name @squash = .fetch(:squash, false) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/fog/core/attributes/default.rb', line 4 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/fog/core/attributes/default.rb', line 4 def name @name end |
#squash ⇒ Object (readonly)
Returns the value of attribute squash.
4 5 6 |
# File 'lib/fog/core/attributes/default.rb', line 4 def squash @squash end |
Instance Method Details
#create ⇒ Object
12 13 14 15 |
# File 'lib/fog/core/attributes/default.rb', line 12 def create create_setter create_getter end |
#create_getter ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fog/core/attributes/default.rb', line 43 def create_getter model.class_eval <<-EOS, __FILE__, __LINE__ def #{name} if self.class.default_values[:#{name}] && !persisted? return self.class.default_values[:#{name}] end attributes[:#{name}] end EOS end |
#create_setter ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/core/attributes/default.rb', line 17 def create_setter if squash model.class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_data) if new_data.is_a?(Hash) if new_data.has_key?(:'#{squash}') attributes[:#{name}] = new_data[:'#{squash}'] elsif new_data.has_key?("#{squash}") attributes[:#{name}] = new_data["#{squash}"] else attributes[:#{name}] = [ new_data ] end else attributes[:#{name}] = new_data end end EOS else model.class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_#{name}) attributes[:#{name}] = new_#{name} end EOS end end |