Class: PuzzlyApiPlugin::TopicsCollection

Inherits:
Collection show all
Includes:
Singleton
Defined in:
lib/puzzly_api_plugin/collection/topics.rb

Instance Method Summary collapse

Methods inherited from Collection

#add_metadata, #get_by_id, #identities

Methods inherited from JSONable

#copy_to_hash, #to_s

Instance Method Details

#add(document) ⇒ Object



7
8
9
10
# File 'lib/puzzly_api_plugin/collection/topics.rb', line 7

def add(document)
  topic = Topic.create(document)
   topic
end

#get_by_module(mod) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/puzzly_api_plugin/collection/topics.rb', line 22

def get_by_module mod
  topics = []
  mod.consumesTopics.each do |topic_id|
    topic = TopicsCollection.instance.get_by_id topic_id
    topics.push topic
  end

  mod.producesTopics.each do |topic_id|
    topic = TopicsCollection.instance.get_by_id topic_id
    topics.push topic
  end

  topics
end

#get_by_modules(modules) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/puzzly_api_plugin/collection/topics.rb', line 12

def get_by_modules modules
  topics = []
  modules.each do |_id, mod|    
    mod_topics = get_by_module(mod)
    topics = topics + mod_topics
  end

  topics
end

#get_by_schema(schema) ⇒ Object



37
38
39
# File 'lib/puzzly_api_plugin/collection/topics.rb', line 37

def get_by_schema schema
  select { |_id, topic| schema.id == topic.schema_id }
end