# File lib/state_machine/integrations/active_record/versions.rb, line 13 def create_scope(name, scope) if owner_class.respond_to?(:named_scope) name = name.to_sym machine_name = self.name # Since ActiveRecord does not allow direct access to the model # being used within the evaluation of a dynamic named scope, the # scope must be generated manually. It's necessary to have access # to the model so that the state names can be translated to their # associated values and so that inheritance is respected properly. owner_class.named_scope(name) owner_class.scopes[name] = lambda do |model, *states| machine_states = model.state_machine(machine_name).states values = states.flatten.map {|state| machine_states.fetch(state).value} ::ActiveRecord::NamedScope::Scope.new(model, :conditions => scope.call(values)) end end # Prevent the Machine class from wrapping the scope false end