module StateGate::Engine::Scoper
Description¶ ↑
Provides scope helper methods for StateGate::Engine
.
Public Instance Methods
generate_scope_names()
click to toggle source
Generate the scope name to use for each state.
# File lib/state_gate/engine/scoper.rb, line 28 def generate_scope_names @states.each do |state, opts| opts[:scope_name] = "#{@prefix}#{state}#{@suffix}" end # each state end
include_scopes?()
click to toggle source
Returns TRUE if scope methods should be added to the model, otherwise FALSE.
.include_scopes? # => true
# File lib/state_gate/engine/scoper.rb, line 45 def include_scopes? !!@scopes end
no_scopes()
click to toggle source
Disables the generation of Class Scope helpers methods
no_scopes
# File lib/state_gate/engine/scoper.rb, line 20 def no_scopes @scopes = false end
scope_name_for_state(state_name = nil)
click to toggle source
Returns the scope name for the given state. Scope names are generated by concatenating the prefix, state name and suffix
.scope_name_for_state(:active) # => 'active' .scope_name_for_state(:pending) # => 'pending_status' .scope_name_for_state(:archived) # => 'with_archived_status'
# File lib/state_gate/engine/scoper.rb, line 59 def scope_name_for_state(state_name = nil) state = assert_valid_state!(state_name) @states[state][:scope_name] end