Class: Objbot

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

Class Method Summary collapse

Class Method Details

.define(&block) ⇒ Object



16
17
18
19
20
# File 'lib/objbot.rb', line 16

def self.define(&block)
  @@objs = {}
  @@context = []
  instance_eval(&block)
end

.last_objObject



23
24
25
# File 'lib/objbot.rb', line 23

def last_obj
  @@context.last[1]
end

.method_missing(method, *args, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/objbot.rb', line 2

def self.method_missing(method, *args, &block)
  case method
  when :obj
    obj = Obj.new args[0]
    @@context.push [method, obj]
    self.instance_eval(&block) if block_given?
    @@context.pop
  when :str
    last_obj.add_field method, *args 
  when :many, :one
    last_obj.add_relationship args[0], args[1], method
  end
end