Module: ObjectiveRuby::ClassMethods

Defined in:
lib/objective-ruby.rb

Instance Method Summary collapse

Instance Method Details

#objc(method, input = {}, &block) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/objective-ruby.rb', line 61

def objc method, input = {}, &block 
  define_method(method)  do |method_input = {}| 
    block_input = {}
    method_input.each do |k,v| 
      if input[k].nil? 
        raise ArgumentError.new "invalid input field #{k}"
      end 

      unless v.is_a? input[k][1]
        raise ArgumentError.new "invalid type for #{k} expected #{input[k][1]}"
      end 

      block_input[input[k][0]] = v
    end
 
    input.each do |k,v|
      if block_input[v[0]].nil?
        raise ArgumentError.new "missing input field #{k}"
      end
    end

    self.instance_exec block_input, &block 
  end
end

#objc_d(method, input = {}, &block) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/objective-ruby.rb', line 86

def objc_d method, input = {}, &block 
  define_method(method)  do |method_input = {}| 
    block_input = {}
    method_input.each do |k,v| 
      if input[k].nil? 
        raise ArgumentError.new "invalid input field #{k}"
      end 

      block_input[input[k]] = v
    end
 
    input.each do |k,v|
      if block_input[v].nil?
        raise ArgumentError.new "missing input field #{k}"
      end
    end

    self.instance_exec block_input, &block 
  end
end

#objr(method, input = {}, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/objective-ruby.rb', line 11

def objr method, input = {}, &block 
  define_method(method)  do |method_input = {}| 
    block_input = {}
    method_input.each do |k,v| 
      new_key = k.to_s.sub!(/(with_|and_)/, '').to_sym

      if input[new_key].nil? 
        raise ArgumentError.new "invalid input field #{new_key}"
      end 

      unless v.is_a? input[new_key]
        raise ArgumentError.new "invalid type for #{new_key} expected #{input[new_key]}"
      end 

      block_input[new_key] = v
    end

    input.each do |k,v|
      if block_input[k].nil?
        raise ArgumentError.new "missing input field #{k}"
      end
    end

    self.instance_exec block_input, &block 
  end
end

#objr_d(method, input = {}, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/objective-ruby.rb', line 38

def objr_d method, input = {}, &block 
  define_method(method)  do |method_input = {}| 
    block_input = {}
    method_input.each do |k,v| 
      new_key = k.to_s.sub!(/(with_|and_)/, '').to_sym

      if input.index(new_key).nil? 
        raise ArgumentError.new "invalid input field #{new_key}"
      end 

      block_input[new_key] = v
    end

    input.each do |k,v|
      if block_input[k].nil?
        raise ArgumentError.new "missing input field #{k}"
      end
    end

    self.instance_exec block_input, &block 
  end
end