Class: Orchestrate::Application::Schema
- Inherits:
-
Object
- Object
- Orchestrate::Application::Schema
- Includes:
- Singleton
- Defined in:
- lib/orchestrate_application/schema.rb
Overview
Singleton class to define schema for Orchestrate.io application
Direct Known Subclasses
Instance Method Summary collapse
- #collection_names ⇒ Object
- #collections ⇒ Object
- #define_collection(args) ⇒ Object
- #define_event_type(collection_name, event_type, properties) ⇒ Object
- #define_graph(collection_name, relation_kind, to_collection) ⇒ Object
- #get(collection_name) ⇒ Object
- #get_collection(name) ⇒ Object
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
-
#load(schema) ⇒ Object
Support (optional) loading of schema from a definition file.
- #load_collection(collection) ⇒ Object
- #schema ⇒ Object
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
9 10 11 |
# File 'lib/orchestrate_application/schema.rb', line 9 def initialize @@schema = {} end |
Instance Method Details
#collection_names ⇒ Object
21 22 23 |
# File 'lib/orchestrate_application/schema.rb', line 21 def collection_names schema.keys end |
#collections ⇒ Object
17 18 19 |
# File 'lib/orchestrate_application/schema.rb', line 17 def collections schema end |
#define_collection(args) ⇒ Object
37 38 39 |
# File 'lib/orchestrate_application/schema.rb', line 37 def define_collection(args) load_collection SchemaCollection.new(args) end |
#define_event_type(collection_name, event_type, properties) ⇒ Object
41 42 43 |
# File 'lib/orchestrate_application/schema.rb', line 41 def define_event_type(collection_name, event_type, properties) get(collection_name).define_event_type event_type, properties end |
#define_graph(collection_name, relation_kind, to_collection) ⇒ Object
45 46 47 |
# File 'lib/orchestrate_application/schema.rb', line 45 def define_graph(collection_name, relation_kind, to_collection) get(collection_name).define_graph relation_kind, to_collection end |
#get(collection_name) ⇒ Object
25 26 27 |
# File 'lib/orchestrate_application/schema.rb', line 25 def get(collection_name) schema[collection_name] end |
#get_collection(name) ⇒ Object
29 30 31 |
# File 'lib/orchestrate_application/schema.rb', line 29 def get_collection(name) get(name) end |
#load(schema) ⇒ Object
Support (optional) loading of schema from a definition file
Example usage:
Orchestrate::Application::Schema.instance.load "./schema.rb"
Example definition file - i.e. "<APP-ROOT>/schema.rb"
Orchestrate::Application::Schema.instance.define_collection(
:name => 'films',
:properties => [ :Title, :Year, :Rated, :Released,
:Runtime, :Genre, :Director, :Writer,
:Actors, :Plot, :Poster, :imdbRating,
:imdbVotes, :imdbID, :Type, :Response ],
:event_types => [ :comments ],
:graphs => [ :sequel ],
)
Orchestrate::Application::Schema.instance.define_event_type(
:collection => 'films',
:event_type => :comments,
:properties => [ :User, :Comment ]
)
Orchestrate::Application::Schema.instance.define_graph(
:collection => 'films',
:relation_kind => :sequel,
:to_collection => 'films',
)
79 80 81 |
# File 'lib/orchestrate_application/schema.rb', line 79 def load(schema) require schema end |
#load_collection(collection) ⇒ Object
33 34 35 |
# File 'lib/orchestrate_application/schema.rb', line 33 def load_collection(collection) schema[collection.name] = collection end |
#schema ⇒ Object
13 14 15 |
# File 'lib/orchestrate_application/schema.rb', line 13 def schema @@schema end |