Class: PuzzlyApiPlugin::SchemaView

Inherits:
Renderable show all
Defined in:
lib/puzzly_api_plugin/view/schema.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Renderable

#apis, #caches, #contexts, #modules, #path, #queries, #render, #schemas, #tables, #topics

Methods inherited from JSONable

#copy_to_hash, #to_s

Constructor Details

#initialize(context, schema, topics, caches) ⇒ SchemaView

Returns a new instance of SchemaView.



17
18
19
20
21
22
23
24
# File 'lib/puzzly_api_plugin/view/schema.rb', line 17

def initialize(context, schema, topics, caches)
  schema.copy_to_hash self
  self.delete MetadataFields::CONTEXT_ID
  
  self[MetadataFields::CONTEXT] = context
  self.topics topics
  self.caches caches
end

Class Method Details

.create(schema) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/puzzly_api_plugin/view/schema.rb', line 5

def self.create(schema)
  context = ContextsCollection.instance.get_by_id schema.context_id
  
  caches = CachesCollection.instance.get_by_schema schema
  topics = TopicsCollection.instance.get_by_schema schema

  SchemaView.new( context.to_identity,
                  schema, 
                  topics.map { |_id, topic| topic.to_identity },
                  caches.map {|_id, cache| cache.to_identity})
end