Sha256: 60549a4da0eaeefd75e95f99bdc12340e647191c41ed463fa07f30a262aebb01

Contents?: true

Size: 903 Bytes

Versions: 15

Compression:

Stored size: 903 Bytes

Contents

module Ecoportal
  module API
    module Common
      module BaseClass
        def redef_without_warning(const, value)
          self.class.send(:remove_const, const) if self.class.const_defined?(const)
          self.class.const_set(const, value)
        end

        def class_resolver(name, klass)
          define_singleton_method(name) { resolve_class(klass) }
          define_method(name) { self.class.resolve_class(klass) }
        end

        def resolve_class(klass)
          @resolved ||= {}
          @resolved[klass] ||=
            case klass
              when Class
                klass
              when String
                Kernel.const_get(klass)
              when Symbol
                resolve_class(self.send(klass))
              else
                raise "Unknown class: #{klass}"
            end
        end

      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ecoportal-api-0.10.8 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.10.7 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.10.6 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.10.5 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.10.4 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.10.3 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.10.2 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.10.1 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.10.0 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.9.7 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.9.6 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.9.5 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.9.4 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.9.3 lib/ecoportal/api/common/base_class.rb
ecoportal-api-0.9.2 lib/ecoportal/api/common/base_class.rb