Module: Tramway::Collections::Helper

Defined in:
lib/tramway/collections/helper.rb

Instance Method Summary collapse

Instance Method Details

#collection_list_by(name:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tramway/collections/helper.rb', line 6

def collection_list_by(name:)
  begin
    require name # needed to load class name with collection
  rescue LoadError
    raise "No such file #{name}. You should create file in the `lib/#{name}.rb` or elsewhere you want"
  end
  unless ::Tramway::Collection.descendants.map(&:to_s).include?(name.camelize)
    ::Tramway::Error.raise_error(
      :tramway, :collections, :helper, :collection_list_by, :there_no_such_collection,
      name_camelize: name.camelize
    )
  end

  name.camelize.constantize.list
end