Class: Husky::Entity
- Inherits:
-
Object
- Object
- 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) ⇒ Entity
constructor
A new instance of Entity.
- #set_basic_attributes_from_hash(hash) ⇒ Object
Constructor Details
#initialize(data) ⇒ Entity
Returns a new instance of Entity.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/husky/entity.rb', line 21 def initialize(data) 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 end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'lib/husky/entity.rb', line 19 def data @data end |
Class Method Details
.new(data = nil) ⇒ Object
11 12 13 14 15 |
# File 'lib/husky/entity.rb', line 11 def new(data = nil) instance = allocate instance.initialize(data) instance end |
.wrap(items) ⇒ Object
7 8 9 |
# File 'lib/husky/entity.rb', line 7 def wrap(items) items.map { |item| new(item) } end |
Instance Method Details
#set_basic_attributes_from_hash(hash) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/husky/entity.rb', line 39 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 |