Sha256: 0c43b541aa15398502e9ceb1a555b2c7896cbf167be4c84f2e9920e91c467265

Contents?: true

Size: 830 Bytes

Versions: 10

Compression:

Stored size: 830 Bytes

Contents

module Rake
  module Funnel
    module Support
      module InstantiateSymbol
        def self.included(klass)
          klass.extend(ClassMethods)
          klass.send(:instantiate, klass)
        end

        module ClassMethods
          attr_reader :module

          private
          def instantiate(mod)
            @module = mod
          end
        end

        private
        def create(sym, *args)
          return sym unless sym.is_a?(Symbol)

          begin
            type = self.class.module.const_get(sym)
          rescue NameError
            raise NameError, "Unknown type to instantiate: #{sym.inspect}. Available types are: #{available.inspect}"
          end

          type.new(*args)
        end

        def available
          self.class.module.constants.sort
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rake-funnel-0.11.0.pre lib/rake/funnel/support/internal/instantiate_symbol.rb
rake-funnel-0.10.0.pre lib/rake/funnel/support/internal/instantiate_symbol.rb
rake-funnel-0.9.1.pre lib/rake/funnel/support/internal/instantiate_symbol.rb
rake-funnel-0.9.0.pre lib/rake/funnel/support/internal/instantiate_symbol.rb
rake-funnel-0.8.0.pre lib/rake/funnel/support/internal/instantiate_symbol.rb
rake-funnel-0.7.0.pre lib/rake/funnel/support/internal/instantiate_symbol.rb
rake-funnel-0.6.1.pre lib/rake/funnel/support/internal/instantiate_symbol.rb
rake-funnel-0.6.0.pre lib/rake/funnel/support/internal/instantiate_symbol.rb
rake-funnel-0.5.0.pre lib/rake/funnel/support/internal/instantiate_symbol.rb
rake-funnel-0.4.0.pre lib/rake/funnel/support/internal/instantiate_symbol.rb