Sha256: 83f2198811aa276e8b3d8f32049c25b32538e1dcc983069de3b7b3cc20c2cf9a

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Lolita
  module Configuration
    module Factory
      
      def temp_object?
        @create_temp_object||=false
        @create_temp_object
      end

      def add(dbi,*args,&block)
        @create_temp_object=true
        begin
          temp_object=self.new(dbi,*args,&block)
        rescue Exception => e
          raise e
        ensure
          @create_temp_object=false
        end
        factory(temp_object.type).new(dbi,*args,&block)
      end


      protected

      def factory(name)
        begin
          Lolita::Configuration.const_get(:"#{to_class(name)}#{factory_name}")
        rescue
          error_class=Lolita.const_get(:"#{factory_name}NotFoundError")
          raise error_class, "Can't find field Lolita::Configuration::#{to_class(name)}#{factory_name}. Add in /configuration/#{factory_name.downcase}/#{name.to_s.downcase}.rb"
        end
      end

      def to_class(name)
        name.to_s.downcase.gsub(/_\w/) do |m|
          m.gsub("_","").upcase
        end.humanize
      end

      def factory_name
        @factory_name||=self.to_s.split("::").last
        @factory_name
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lolita-3.0.7 lib/lolita/configuration/factory.rb
lolita-3.0.6 lib/lolita/configuration/factory.rb