base/maroon_base.rb in maroon-0.7.1 vs base/maroon_base.rb in maroon-0.8.0

- old
+ new

@@ -8,11 +8,11 @@ # a role can be defined much like a context. instead of calling the define method call the role method followed by the role name (as a symbol) # the role will be used for a private instance variable and the naming convention should match this # With in the block supplied to the role method you can define role methods the same way as you define interactions. See the method who # in the below example # = Example -# Context::define :Greeter do +# Context.define :Greeter do # role :who do # say do # @who #could be self as well to refer to the current role player of the 'who' role # end # end @@ -37,29 +37,68 @@ def self.define(*args, &block) name, base_class, default_interaction = *args + if default_interaction and (not base_class.instance_of?(Class)) then base_class = eval(base_class.to_s) end if base_class and ((not default_interaction) and (not base_class.instance_of?(Class))) then base_class, default_interaction = default_interaction, base_class end - @@with_contracts ||= nil - @@generate_file_path ||= nil - ctx = self.send(:create_context_factory, name, base_class, default_interaction, block) - transformer = Transformer.new name, ctx.roles,ctx.interactions,ctx.private_interactions,base_class, default_interaction - return transformer.transform @@generate_file_path, @@with_contracts + @with_contracts ||= nil + + ctx = self.send(:create_context_factory, name, base_class, default_interaction, block) + + if self.generate_dependency_graph + dependencies = {} + ctx.dependencies = DependencyGraphModel.new(DependencyGraph.new(name,ctx.roles,ctx.interactions,dependencies).create!) + end + transformer = Transformer.new(name, ctx.roles, ctx.interactions, ctx.private_interactions, base_class, default_interaction) + ctx.generated_class = transformer.transform(generate_files_in, @with_contracts) + ctx end - def self.generate_files_in(*args, &b) + def self.generate_files_in + @generate_files_in + end - @@generate_file_path = args[0] + def self.generate_files_in=(folder) + @generate_files_in = folder + end + def self.generate_code=(value) + @generate_code = value end + def self.generate_dependency_graph=(value) + @generate_dependency_graph = value + end + + def self.generate_code + @generate_code || !generate_dependency_graph || generate_files_in + end + + def self.generate_dependency_graph + @generate_dependency_graph + end + + def dependencies + @dependencies + end + def generated_class + @generated_class + end + + def dependencies=(value) + @dependencies=value + end + def generated_class=(value) + @generated_class=value + end + def roles @roles end def interactions @interactions @@ -114,15 +153,15 @@ ctx end def self.with_contracts(*args) - return @@with_contracts if (args.length == 0) + return @with_contracts if (args.length == 0) value = args[0] - if @@with_contracts and (not value) then + if @with_contracts and (not value) then raise('make up your mind! disabling contracts during execution will result in undefined behavior') end - @@with_contracts = value + @with_contracts = value end def is_definition?(exp) exp && (exp[0] == :defn || exp[0] == :defs)