module Fog::Attributes::ClassMethods
Public Instance Methods
_load(marshalled)
click to toggle source
# File lib/fog/core/attributes.rb, line 5 def _load(marshalled) new(Marshal.load(marshalled)) end
aliases()
click to toggle source
# File lib/fog/core/attributes.rb, line 9 def aliases @aliases ||= {} end
attribute(name, options = {})
click to toggle source
# File lib/fog/core/attributes.rb, line 17 def attribute(name, options = {}) class_eval <<-EOS, __FILE__, __LINE__ def #{name} attributes[:#{name}] end EOS case options[:type] when :boolean class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_#{name}) attributes[:#{name}] = case new_#{name} when true,'true' true when false,'false' false end end EOS when :float class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_#{name}) attributes[:#{name}] = new_#{name}.to_f end EOS when :integer class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_#{name}) attributes[:#{name}] = new_#{name}.to_i end EOS when :string class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_#{name}) attributes[:#{name}] = new_#{name}.to_s end EOS when :time class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_#{name}) attributes[:#{name}] = if new_#{name}.nil? || new_#{name} == "" || new_#{name}.is_a?(Time) new_#{name} else Time.parse(new_#{name}) end end EOS when :array class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_#{name}) attributes[:#{name}] = [*new_#{name}] end EOS else if squash = options[:squash] 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 class_eval <<-EOS, __FILE__, __LINE__ def #{name}=(new_#{name}) attributes[:#{name}] = new_#{name} end EOS end end @attributes ||= [] @attributes |= [name] for new_alias in [*options[:aliases]] aliases[new_alias] = name end end
attributes()
click to toggle source
# File lib/fog/core/attributes.rb, line 13 def attributes @attributes ||= [] end
identity(name, options = {})
click to toggle source
# File lib/fog/core/attributes.rb, line 101 def identity(name, options = {}) @identity = name self.attribute(name, options) end
ignore_attributes(*args)
click to toggle source
# File lib/fog/core/attributes.rb, line 106 def ignore_attributes(*args) @ignored_attributes = args.collect {|attr| attr.to_s } end
ignored_attributes()
click to toggle source
# File lib/fog/core/attributes.rb, line 110 def ignored_attributes @ignored_attributes ||= [] end