Class: Entity::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/entity_rb/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
# File 'lib/entity_rb/base.rb', line 5

def initialize(args={})
  initialize_attributes(args || {})

  set_attributes(args)
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'lib/entity_rb/base.rb', line 3

def attributes
  @attributes
end

Class Method Details

.fieldsObject



34
35
36
37
38
39
40
# File 'lib/entity_rb/base.rb', line 34

def self.fields
  return @fields if @fields

  @fields = parent && parent.respond_to?(:fields) ? parent.fields.dup : []

  field @fields
end

Instance Method Details

#fieldsObject



42
43
44
# File 'lib/entity_rb/base.rb', line 42

def fields
  self.class.fields
end

#set_attributes(args) ⇒ Object



11
12
# File 'lib/entity_rb/base.rb', line 11

def set_attributes(args)
end

#to_hObject Also known as: to_hash



24
25
26
27
28
29
30
# File 'lib/entity_rb/base.rb', line 24

def to_h
  {}.tap do |hash|
    fields.each do |key|
      hash[key] = send(key) unless send(key).nil?
    end
  end
end