lib/finitio/system.rb in finitio-0.4.1 vs lib/finitio/system.rb in finitio-0.5.0

- old
+ new

@@ -2,47 +2,47 @@ # # A System is a collection of named Finitio types. # class System - def initialize(types = {}, main = nil) + def initialize(types = {}) @types = types - @main = main end - attr_accessor :main - DSL_METHODS.each do |dsl_method| - define_method(dsl_method){|*args, &bl| - factory.public_send(dsl_method, *args, &bl) - } - end + def add_type(type, name = nil, metadata = nil) + type = factory.type(type, name, metadata) - def add_type(type) - unless type.is_a?(Type) - raise ArgumentError, "Finitio::Type expected, got `#{type}`" - end - if @types.has_key?(type.name) raise Error, "Duplicate type name `#{type.name}`" end @types[type.name] = type end def get_type(name) - @types[name] + @types[name] || @types[name.to_s] end alias :[] :get_type + def main + self['Main'] + end + def fetch(name, &bl) @types.fetch(name, &bl) end def factory @factory ||= TypeFactory.new end + TypeFactory::DSL_METHODS.each do |dsl_method| + define_method(dsl_method){|*args, &bl| + factory.public_send(dsl_method, *args, &bl) + } + end + def dress(*args, &bl) raise Error, "No main type." unless main main.dress(*args, &bl) end @@ -54,10 +54,10 @@ def inspect @types.each_pair.map{|k,v| "#{k} = #{v}" }.join("\n") end def dup - System.new(@types.dup, @main) + System.new(@types.dup) end end # class System end # module Finitio