Module ConstantNamedScopesModule::ClassMethods
In: lib/modules/constant_named_scopes_module.rb

Class methods

Methods

Public Instance methods

Creates named scopes for the given constants.

Argument is the name of the attribute for which the syms exist, the syms are in an array ATTRIBUTE_NAME_SYMS holding things like :document, :point. A hash translating the syms to integers or what ever might be found in the database for them should be named ATTRIBUTE_NAMES (plural of attribute_name).

For ‘mode’, in a class with MODE_SYMS = [:document] and MODES => {:document => 1}, it returns a named scope called document_modes, that returns all document having mode 1 in the db.

[Source]

    # File lib/modules/constant_named_scopes_module.rb, line 30
30:     def constant_named_scopes(*attribute_names)
31:       attribute_names.each do |attribute_name|
32:         attribute_name = attribute_name.to_s
33:         eval "          Const::\#{self.to_s}::\#{attribute_name.upcase}_SYMS.each do |sym| \n            named_scope((sym.to_s + '_\#{attribute_name.pluralize}').to_sym,\n                :conditions => {:\#{attribute_name} => Const::\#{self.to_s}::\#{attribute_name.pluralize.upcase}[sym]})\n          end\n"
34:       end
35:     end

[Validate]