Module: Ecoportal::API::Common::BaseClass

Included in:
BaseModel, V1, V1::People, V1::PersonSchemas
Defined in:
lib/ecoportal/api/common/base_class.rb

Instance Method Summary collapse

Instance Method Details

#class_resolver(name, klass) ⇒ Object



10
11
12
13
# File 'lib/ecoportal/api/common/base_class.rb', line 10

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

#redef_without_warning(const, value) ⇒ Object



5
6
7
8
# File 'lib/ecoportal/api/common/base_class.rb', line 5

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

#resolve_class(klass) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ecoportal/api/common/base_class.rb', line 15

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