Class: Husky::Entity
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Husky::Entity
- Defined in:
- lib/husky/entity.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data = nil) ⇒ Entity
constructor
A new instance of Entity.
- #set_basic_attributes_from_hash(hash) ⇒ Object
Constructor Details
#initialize(data = nil) ⇒ Entity
Returns a new instance of Entity.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/husky/entity.rb', line 23 def initialize(data = nil) if data.nil? # do nothing elsif data.is_a? Hash post_data.each_pair do |key, value| instance_variable_set("@#{key}", value) end post_data.each_pair do |key, value| self.class.send(:define_method, key) do instance_variable_get("@#{key}") end end else @data = data super end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
21 22 23 |
# File 'lib/husky/entity.rb', line 21 def data @data end |
Class Method Details
.new(data) ⇒ Object
13 14 15 16 17 |
# File 'lib/husky/entity.rb', line 13 def new(data) instance = allocate instance.initialize(data) instance end |
.wrap(items) ⇒ Object
9 10 11 |
# File 'lib/husky/entity.rb', line 9 def wrap(items) items.map { |item| new(item) } end |
Instance Method Details
#set_basic_attributes_from_hash(hash) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/husky/entity.rb', line 42 def set_basic_attributes_from_hash(hash) hash.each_pair do |key, value| unless value.respond_to? :each instance_variable_set("@#{key}", value) end end hash.each_pair do |key, value| unless value.respond_to? :each self.class.send(:define_method, key) do instance_variable_get("@#{key}") end end end end |