Class: RomFactory::Struct

Inherits:
Object
  • Object
show all
Defined in:
lib/rom_factory/struct.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Struct

Returns a new instance of Struct.



3
4
5
6
7
# File 'lib/rom_factory/struct.rb', line 3

def initialize(values)
  @values = values
  define_methods
  set_values
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



9
10
11
# File 'lib/rom_factory/struct.rb', line 9

def schema
  @schema
end

#valuesObject (readonly)

Returns the value of attribute values.



9
10
11
# File 'lib/rom_factory/struct.rb', line 9

def values
  @values
end

Instance Method Details

#define_methodsObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rom_factory/struct.rb', line 11

def define_methods
  values.each {|k,v|
    define_singleton_method k, Proc.new {
      instance_variable_get("@#{k}")
    }

    define_singleton_method "#{k}=", Proc.new {|v|
      instance_variable_set("@#{k}", v)
    }
  }
end

#set_valuesObject



23
24
25
26
27
# File 'lib/rom_factory/struct.rb', line 23

def set_values
  values.each do |k, v|
    send("#{k}=", v)
  end
end

#to_hObject



33
34
35
# File 'lib/rom_factory/struct.rb', line 33

def to_h
  values
end

#to_hashObject



29
30
31
# File 'lib/rom_factory/struct.rb', line 29

def to_hash
  to_h
end