Module: ActiveCollection::MemberClass::ClassMethods

Defined in:
lib/active_collection/member_class.rb

Instance Method Summary collapse

Instance Method Details

#human_name(*args) ⇒ Object

Plural human name of the member class.



41
42
43
# File 'lib/active_collection/member_class.rb', line 41

def human_name(*args)
  model_class.human_name(*args).pluralize
end

#model(model_name) ⇒ Object

If the name of the class held by your collection cannot be derived from the name of the collection class (by removing the word Collection from the end of the collection class name) then use model to set it.

Example:

class WeirdNamedCollection
  model "Normal"
end

This will use the class Normal to do counts and finds.



20
21
22
# File 'lib/active_collection/member_class.rb', line 20

def model(model_name)
  (@model_class_name = model_name) && @model_class = nil
end

#model_classObject

The actual member class.

Prints a useful error message if you define your model class wrong.



27
28
29
30
31
32
33
# File 'lib/active_collection/member_class.rb', line 27

def model_class
  begin
    @model_class ||= model_class_name.constantize
  rescue NameError => e
    raise NameError, %|#{e} - Use 'model "Class"' in the collection to declare the correct model class for #{name}|
  end
end

#model_class_nameObject



45
46
47
48
49
# File 'lib/active_collection/member_class.rb', line 45

def model_class_name
  @model_class_name ||
    (superclass != ActiveCollection::Base && superclass.model_class_name) ||
    name.sub(/Collection$/,'')
end

#table_nameObject

Table name of the member class.



36
37
38
# File 'lib/active_collection/member_class.rb', line 36

def table_name
  model_class.table_name
end