Class: PostJson::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/post_json.rb

Defined Under Namespace

Modules: Proxy

Class Method Summary collapse

Class Method Details

.[](collection_name) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/post_json.rb', line 36

def [](collection_name)
  name_digest = PostJson::ModelSettings.collection_name_digest(collection_name)
  class_name = "Collection_#{name_digest}"
  model_class = Proxy.const_get(class_name)
  model_class.collection_name = collection_name
  model_class
end

.each(&block) ⇒ Object


52
53
54
# File 'lib/post_json.rb', line 52

def each(&block)
  to_a.each(&block)
end

.namesObject


44
45
46
# File 'lib/post_json.rb', line 44

def names
  ModelSettings.order('collection_name').pluck('collection_name')
end

.to_aObject


48
49
50
# File 'lib/post_json.rb', line 48

def to_a
  names.map { |collection_name| self[collection_name] }
end