Class: Fog::Attributes::Default
- Inherits:
-
Object
- Object
- Fog::Attributes::Default
- Defined in:
- lib/fog/core/attributes/default.rb
Overview
Fog Default Attribute
This class handles the attributes without a type force. The attributes returned from the provider will keep its original values.
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#as ⇒ Object
readonly
Returns the value of attribute as.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#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_aliases ⇒ Object
- #create_getter ⇒ Object
- #create_mask ⇒ Object
- #create_setter ⇒ Object
-
#initialize(model, name, options) ⇒ Default
constructor
A new instance of Default.
- #set_defaults ⇒ Object
Constructor Details
#initialize(model, name, options) ⇒ Default
Returns a new instance of Default.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/core/attributes/default.rb', line 10 def initialize(model, name, ) @model = model @model.attributes << name @name = name @squash = .fetch(:squash, false) @aliases = .fetch(:aliases, []) @default = [:default] @as = .fetch(:as, name) create_setter create_getter create_aliases set_defaults create_mask end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
8 9 10 |
# File 'lib/fog/core/attributes/default.rb', line 8 def aliases @aliases end |
#as ⇒ Object (readonly)
Returns the value of attribute as.
8 9 10 |
# File 'lib/fog/core/attributes/default.rb', line 8 def as @as end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
8 9 10 |
# File 'lib/fog/core/attributes/default.rb', line 8 def default @default end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/fog/core/attributes/default.rb', line 8 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/fog/core/attributes/default.rb', line 8 def name @name end |
#squash ⇒ Object (readonly)
Returns the value of attribute squash.
8 9 10 |
# File 'lib/fog/core/attributes/default.rb', line 8 def squash @squash end |
Instance Method Details
#create_aliases ⇒ Object
63 64 65 66 67 |
# File 'lib/fog/core/attributes/default.rb', line 63 def create_aliases Array(aliases).each do |alias_name| model.aliases[alias_name] = name end end |
#create_getter ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/core/attributes/default.rb', line 51 def create_getter model.class_eval " def \#{name}\n return attributes[:\#{name}] unless attributes[:\#{name}].nil?\n if !attributes.key?(:\#{name}) && !self.class.default_values[:\#{name}].nil? && !persisted?\n return self.class.default_values[:\#{name}]\n end\n attributes[:\#{name}]\n end\n EOS\nend\n", __FILE__, __LINE__ |
#create_mask ⇒ Object
73 74 75 |
# File 'lib/fog/core/attributes/default.rb', line 73 def create_mask model.masks[name] = as end |
#create_setter ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/core/attributes/default.rb', line 25 def create_setter if squash model.class_eval " def \#{name}=(new_data)\n if new_data.is_a?(Hash)\n if new_data.has_key?(:'\#{squash}')\n attributes[:\#{name}] = new_data[:'\#{squash}']\n elsif new_data.has_key?(\"\#{squash}\")\n attributes[:\#{name}] = new_data[\"\#{squash}\"]\n else\n attributes[:\#{name}] = [ new_data ]\n end\n else\n attributes[:\#{name}] = new_data\n end\n end\n EOS\n else\n model.class_eval <<-EOS, __FILE__, __LINE__\n def \#{name}=(new_\#{name})\n attributes[:\#{name}] = new_\#{name}\n end\n EOS\n end\nend\n", __FILE__, __LINE__ |
#set_defaults ⇒ Object
69 70 71 |
# File 'lib/fog/core/attributes/default.rb', line 69 def set_defaults model.default_values[name] = default unless default.nil? end |