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

Instance Method Details

#generate_scope_namesObject

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.

Examples:

.include_scopes?  #=> true

Returns:

  • (Boolean)


49
50
51
# File 'lib/state_gate/engine/scoper.rb', line 49

def include_scopes?
  !!@scopes
end

#no_scopesObject

Disables the generation of Class Scope helpers methods

Examples:

no_scopes


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'

Parameters:

  • state_name (Symbol) (defaults to: nil)

    the state to generate the scope_name for



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