Class: TicketEvolution::Builder

Inherits:
OpenStruct
  • Object
show all
Includes:
SingularClass
Defined in:
lib/ticket_evolution/core/builder.rb

Direct Known Subclasses

Datum, Model

Instance Method Summary collapse

Methods included from SingularClass

#singular_class

Constructor Details

#initialize(hash = {}) ⇒ Builder

Returns a new instance of Builder.



5
6
7
8
9
10
11
12
# File 'lib/ticket_evolution/core/builder.rb', line 5

def initialize(hash={})
  attrs = hash.clone
  @table = attrs['id'].present? ? {:id => attrs.delete('id')} : {}
  attrs.each do |k, v|
    @table[k.to_sym] = process_datum(v, k)
    new_ostruct_member(k)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object (private)



56
57
58
59
60
61
62
63
64
# File 'lib/ticket_evolution/core/builder.rb', line 56

def method_missing(meth, *args)
  if args.size == 1
    super(meth, process_datum(args.first, meth))
  elsif args.size == 0
    super(meth)
  else
    super(meth, process_datum(args, meth))
  end
end

Instance Method Details

#idObject



27
28
29
# File 'lib/ticket_evolution/core/builder.rb', line 27

def id
  @table[:id]
end

#id=(id) ⇒ Object

Ruby 1.8.7 / REE compatibility



23
24
25
# File 'lib/ticket_evolution/core/builder.rb', line 23

def id=(id)
  @table[:id] = id
end

#to_hashObject



14
15
16
17
18
19
20
# File 'lib/ticket_evolution/core/builder.rb', line 14

def to_hash
  hash = {}
  @table.each do |k, v|
    hash[k] = from_ostruct(v)
  end
  hash
end