Class: Transformer
- Inherits:
-
Object
- Object
- Transformer
- Defined in:
- lib/Transformer.rb
Instance Method Summary collapse
-
#initialize(context_name, roles, interactions, private_interactions, base_class, default_interaction) ⇒ Transformer
constructor
A new instance of Transformer.
- #transform(file_path, with_contracts) ⇒ Object
Constructor Details
#initialize(context_name, roles, interactions, private_interactions, base_class, default_interaction) ⇒ Transformer
Returns a new instance of Transformer.
2 3 4 5 6 7 8 9 |
# File 'lib/Transformer.rb', line 2 def initialize(context_name,roles,interactions,private_interactions,base_class,default_interaction) @context_name = context_name @roles = roles @interactions = interactions @base_class = base_class @default_interaction = default_interaction @private_interactions = private_interactions @definitions = {} end |
Instance Method Details
#transform(file_path, with_contracts) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/Transformer.rb', line 10 def transform(file_path,with_contracts) code = (self_interactions_generated_source + self_roles_generated_source) if file_path then name = context_name.to_s complete = ((((("class " + name) + (@base_class ? (("<< " + @base_class.name)) : (""))) + "\n ") + code.to_s) + "\n end") File.open((((("./" + file_path.to_s) + "/") + name) + ".rb"), "w") do |f| f.write(complete) end complete else c = @base_class ? (Class.new(base_class)) : (Class.new) if with_contracts then c.class_eval("def self.assert_that(obj)\n ContextAsserter.new(self.contracts,obj)\nend\ndef self.refute_that(obj)\n ContextAsserter.new(self.contracts,obj,false)\nend\ndef self.contracts\n @contracts\nend\ndef self.contracts=(value)\n @contracts = value\nend") c.contracts = contracts end Kernel.const_set(context_name, c) begin temp = c.class_eval(code) rescue SyntaxError p(("error: " + code)) end (temp or c) end end |