Module: ActiveWorker::Behavior::Hashable

Included in:
Configuration
Defined in:
lib/active_worker/behavior/hashable.rb

Instance Method Summary collapse

Instance Method Details

#canonicalize(config, col) ⇒ Object



67
68
69
70
# File 'lib/active_worker/behavior/hashable.rb', line 67

def canonicalize(config, col)
  config["_type"] ||= col.name.classify
  config["_id"] = config["_id"].to_s
end

#get_as_flat_hash_by_root_object(root_object) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/active_worker/behavior/hashable.rb', line 5

def get_as_flat_hash_by_root_object(root_object)
  configs = []
  col = get_mongoid_collection
  col.find("root_object_id" => root_object.id).each do |config|
    canonicalize(config, col)
    configs << config
  end
  configs
end

#get_as_hash_by_root_object(root_object) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/active_worker/behavior/hashable.rb', line 15

def get_as_hash_by_root_object(root_object)
  configs = []
  col = get_mongoid_collection
  col.find("root_object_id" => root_object.id, "parent_configuration_id" => nil).each do |config|
    config["configurations"] = get_children_for(col, config["_id"])
    canonicalize(config, col)
    configs << config
  end
  configs
end

#get_children_for(col, parent_configuration_id) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/active_worker/behavior/hashable.rb', line 26

def get_children_for(col, parent_configuration_id)
  configs = []
  col.find("parent_configuration_id" => parent_configuration_id).each do |config|
    config["configurations"] = get_children_for(col, config["_id"])
    canonicalize(config, col)
    configs << config
  end
  configs
end

#get_mongoid_collectionObject



73
74
75
# File 'lib/active_worker/behavior/hashable.rb', line 73

def get_mongoid_collection
  Mongoid.default_session.collections.select {|c| c.name == self.collection_name.to_s }.first
end

#get_renderable_children_for(col, parent_configuration_id) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/active_worker/behavior/hashable.rb', line 57

def get_renderable_children_for(col, parent_configuration_id)
  configs = []
  col.find("parent_configuration_id" => parent_configuration_id, "renderable" => true).each do |config|
    config["configurations"] = get_renderable_children_for(col, config["_id"])
    canonicalize(config, col)
    configs << config
  end
  configs
end

#get_renderable_hash_by_root_object(root_object) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/active_worker/behavior/hashable.rb', line 38

def get_renderable_hash_by_root_object(root_object)
  configs = []
  col = get_mongoid_collection
  col.find("root_object_id" => root_object.id, "parent_configuration_id" => nil, "renderable" => true).each do |config|
    config["configurations"] = get_renderable_children_for(col, config["_id"])
    canonicalize(config, col)
    configs << config
  end
  configs
end

#renderable_hash_for_configuration(configuration_id) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/active_worker/behavior/hashable.rb', line 49

def renderable_hash_for_configuration(configuration_id)
  col = get_mongoid_collection
  config = col.find("_id" => configuration_id).first
  config["configurations"] = get_renderable_children_for(col, config["_id"])
  canonicalize(config, col)
  config
end