Module: StateGate::Engine::Scoper
- Included in:
- StateGate::Engine
- Defined in:
- lib/state_gate/engine/scoper.rb
Overview
Description
Provides scope helper methods for StateGate::Engine.
Instance Method Summary collapse
-
#generate_scope_names ⇒ Object
Generate the scope name to use for each state.
-
#include_scopes? ⇒ Boolean
Returns TRUE if scope methods should be added to the model, otherwise FALSE.
-
#no_scopes ⇒ Object
Disables the generation of Class Scope helpers methods.
-
#scope_name_for_state(state_name = nil) ⇒ Object
Returns the scope name for the given state.
Instance Method Details
#generate_scope_names ⇒ Object
Generate the scope name to use for each state.
31 32 33 34 35 |
# File 'lib/state_gate/engine/scoper.rb', line 31 def generate_scope_names @states.each do |state, opts| opts[:scope_name] = "#{@prefix}#{state}#{@suffix}" end # each state end |
#include_scopes? ⇒ Boolean
Returns TRUE if scope methods should be added to the model, otherwise FALSE.
49 50 51 |
# File 'lib/state_gate/engine/scoper.rb', line 49 def include_scopes? !!@scopes end |
#no_scopes ⇒ Object
Disables the generation of Class Scope helpers methods
22 23 24 |
# File 'lib/state_gate/engine/scoper.rb', line 22 def no_scopes @scopes = false end |
#scope_name_for_state(state_name = nil) ⇒ Object
Returns the scope name for the given state. Scope names are generated by concatenating the prefix, state name and suffix
Example
.scope_name_for_state(:active) #=> 'active'
.scope_name_for_state(:pending) #=> 'pending_status'
.scope_name_for_state(:archived) #=> 'with_archived_status'
67 68 69 70 |
# File 'lib/state_gate/engine/scoper.rb', line 67 def scope_name_for_state(state_name = nil) state = assert_valid_state!(state_name) @states[state][:scope_name] end |