Module: Cauldron::DynamicOperatorModule
- Defined in:
- lib/cauldron/dynamic_operator_module.rb
Instance Method Summary collapse
- #clone_statement ⇒ Object
- #close ⇒ Object
-
#context_realizable?(context) ⇒ Boolean
def extend_actualized_composite(x, container, examples, point) cloned_container = container.clone_solution cloned_container.add_statement_at(x, point) cloned_container Cauldron::ActualizedComposite.new(cloned_container, examples) end.
- #indexes=(value) ⇒ Object
-
#realizable?(histories, point) ⇒ Boolean
def to_tracking_sexp(operators, scope, caret) raise StandardError.new(‘statement has been instance closed’) unless @closed to_sexp(scope) end.
- #realize(params) ⇒ Object
- #rip(composite, examples) ⇒ Object
- #uses_constants? ⇒ Boolean
- #write_to_file(filename) ⇒ Object
Instance Method Details
#clone_statement ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/cauldron/dynamic_operator_module.rb', line 18 def clone_statement # TODO Need to clone the sexp methods # o = DynamicOperator.new(@information, @sexp_methods) # o.instance_eval(Sorcerer.source(@sexp_methods, indent: true)) # o self.class.new(@indexes.clone) end |
#close ⇒ Object
14 15 16 |
# File 'lib/cauldron/dynamic_operator_module.rb', line 14 def close @closed = true end |
#context_realizable?(context) ⇒ Boolean
def extend_actualized_composite(x, container, examples, point)
cloned_container = container.clone_solution
cloned_container.add_statement_at(x, point)
cloned_container
Cauldron::ActualizedComposite.new(cloned_container, examples)
end
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cauldron/dynamic_operator_module.rb', line 43 def context_realizable?(context) vars = context.keys.select {|x| x.match(/var\d/) } var_names = vars.collect(&:to_s) first_variable = 'var'+@indexes[0].to_s # a = %Q{ # def function(var0) # #{Sorcerer.source(to_sexp(var_names), indent: true)} # end # } # a = %Q{ # def function(var0) # #{Sorcerer.source(to_sexp(Cauldron::Scope.new(var_names), []), indent: true)} # end # } a = %Q{ def function(#{first_variable}) #{Sorcerer.source(to_sexp(Cauldron::Scope.new(var_names), []), indent: true)} end } o = Object.new o.instance_eval(a) begin #o.function(*vars.collect {|x| context[x] }) o.function context[first_variable.to_sym] rescue NoMethodError => e return false rescue StandardError => e puts e return false end return true #o.function(*params.values) # a = %Q{ # def function(var0) # #{Sorcerer.source(to_sexp(Cauldron::Scope.new(['var0'])), indent: true)} # end # } end |
#indexes=(value) ⇒ Object
9 10 11 12 |
# File 'lib/cauldron/dynamic_operator_module.rb', line 9 def indexes=(value) raise StandardError.new('') if @closed @indexes = value end |
#realizable?(histories, point) ⇒ Boolean
def to_tracking_sexp(operators, scope, caret)
raise StandardError.new('statement has been instance closed') unless @closed
to_sexp(scope)
end
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/cauldron/dynamic_operator_module.rb', line 114 def realizable?(histories, point) parameters = histories.variable_permutations(@indexes.length) parameters.each do |params| begin realize(params) rescue => e puts e failed_uses.push(histories) return false end end true rescue => e puts e puts e.backtrace # TODO GENERATE RSPEC TEST with arguments end |
#realize(params) ⇒ Object
132 133 134 135 136 |
# File 'lib/cauldron/dynamic_operator_module.rb', line 132 def realize(params) o = Object.new o.instance_eval(rip2) o.function(*params.values) end |
#rip(composite, examples) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/cauldron/dynamic_operator_module.rb', line 100 def rip(composite,examples) Ripper::SexpBuilder.new( %Q{ def function(var0) #{composite.to_ruby(examples.scope)} end }).parse end |
#uses_constants? ⇒ Boolean
5 6 7 |
# File 'lib/cauldron/dynamic_operator_module.rb', line 5 def uses_constants? @information[:constants] end |
#write_to_file(filename) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/cauldron/dynamic_operator_module.rb', line 91 def write_to_file(filename) File.open( File.join('tmp',filename), 'w+') do |file| file << "class DynamicOperator"+"\n" file << Sorcerer.source(@sexp_methods, indent: true) file << "\n" file << "end" end end |