Module: Freebase::Types

Defined in:
lib/freebase.rb

Overview

This module is a namespace scope for the Freebase domains

Class Method Summary collapse

Class Method Details

.new_freebase_type(name) ⇒ Object

Automagically creates modules for domains and classes for types for matching namespaces to Freebase’s domain/type naming structure. Shouldn’t need to be called manually because this is called by the module whenever the constant is missing.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/freebase.rb', line 20

def new_freebase_type(name)
  Freebase::Api::Logger.trace {"new freebase module = #{name}"}
  self.const_set(name, Module.new do
    def new_freebase_type(name)
      Freebase::Api::Logger.trace {"new freebase class = #{name}"}
      klass = self.const_set(name, Class.new(Freebase::Base))
      klass.class_eval do
        cattr_accessor :properties, :schema_loaded
      end
      returning(klass) do |tc|
        tc.load_schema! unless tc.schema_loaded?
        Freebase::Api::Logger.trace { "Attempting Mixin include: #{tc.name.sub(/Types/,"Mixins")}" }
        begin
          tc.send(:include, tc.name.sub(/Types/,"Mixins").constantize)
        rescue NameError => e
          Freebase::Api::Logger.trace "failed: #{e}"
        end
      end
    end

    module_function :new_freebase_type
  end)
end