Class: Orchestrate::Rails::Schema

Inherits:
Application::Schema show all
Includes:
Singleton
Defined in:
lib/orchestrate_rails/schema.rb

Overview

Extensions to parent class for mapping data between orchestrate and rails.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Application::Schema

#collection_names, #collections, #define_collection, #define_event_type, #define_graph, #get, #get_collection, #initialize, #load, #load_collection, #schema

Constructor Details

This class inherits a constructor from Orchestrate::Application::Schema

Class Method Details

.define_collection(args) ⇒ Object

args: { :name, :properties, :event_types, :graphs, :classname }



73
74
75
76
77
78
79
80
81
# File 'lib/orchestrate_rails/schema.rb', line 73

def self.define_collection(args)
  # puts "DEF_COLL: '#{args.inspect}'"
  coll = instance.load_collection SchemaCollection.new(args) { |c|
    c.classname = args[:classname]
    c.classpath = args[:classpath] #unless args[:classpath].blank?
    c.attr_map = build_attr_map args[:properties]
  }
  # puts "DEF_COLL: '#{coll.classpath}'"
end

.define_event_type(args) ⇒ Object



83
84
85
86
87
88
# File 'lib/orchestrate_rails/schema.rb', line 83

def self.define_event_type(args)
  # puts "DEFINE: inst = '#{instance}', '#{args[:collection]}'"  #JMC
  instance.define_event_type(
    args[:collection], args[:event_type], args[:properties]
  )
end

.define_graph(args) ⇒ Object



90
91
92
93
94
# File 'lib/orchestrate_rails/schema.rb', line 90

def self.define_graph(args)
  instance.define_graph(
    args[:collection], args[:relation_kind], args[:to_collection]
  )
end

.load(schema) ⇒ Object



67
68
69
# File 'lib/orchestrate_rails/schema.rb', line 67

def self.load(schema)
  require Rails.root.join schema
end

Instance Method Details

#attr_map(collection_name) ⇒ Object

Returns the table that maps attribute names to property names.

Property names are the original key names in json documents stored in orchestrate collections - before they are converted to the snake_case style used for model attribute names. Property names can be mapped to attribute names by using ::String#to_orchio_rails_attr or ::Symbol#to_orchio_rails_attr.



29
30
31
# File 'lib/orchestrate_rails/schema.rb', line 29

def attr_map(collection_name)
  get_collection(collection_name).attr_map
end

#attrs(collection_name) ⇒ Object



18
19
20
# File 'lib/orchestrate_rails/schema.rb', line 18

def attrs(collection_name)
  get_collection(collection_name).attr_map.keys
end

#classname(collection_name) ⇒ Object



40
41
42
# File 'lib/orchestrate_rails/schema.rb', line 40

def classname(collection_name)
  get_collection(collection_name).classname
end

#fullclassname(collection_name) ⇒ Object



44
45
46
47
# File 'lib/orchestrate_rails/schema.rb', line 44

def fullclassname(collection_name)
  c = get_collection(collection_name)
  c.classpath.nil? ? c.classname : "#{c.classpath}::#{c.classname}"
end

#get_collection_from_class(classname) ⇒ Object



49
50
51
52
# File 'lib/orchestrate_rails/schema.rb', line 49

def get_collection_from_class(classname)
  classname = classname.split('::').last
  collections.values.each { |c| return c if c.classname == classname }
end

#properties(collection_name) ⇒ Object



14
15
16
# File 'lib/orchestrate_rails/schema.rb', line 14

def properties(collection_name)
  get_collection(collection_name).properties
end

#qmap(collection_name) ⇒ Object

Returns a table that maps attribute names to property names. And the mapping conveniently works even when the attribute name is actually a property name.



36
37
38
# File 'lib/orchestrate_rails/schema.rb', line 36

def qmap(collection_name)
  get_collection(collection_name).qmap ||= build_query_map(collection_name)
end