Module: StateGate::Engine::Fixer

Included in:
StateGate::Engine
Defined in:
lib/state_gate/engine/fixer.rb

Overview

Description

Provides prefix and suffix helper methods for StateGate::Engine.

Instance Method Summary collapse

Instance Method Details

#prefix(val = nil) ⇒ Object

A phrase to add before state names when using Class Scopes. This helps differential attributes that have similar state names.

Examples:

prefix :before  #=> Class.before_active

Parameters:

  • val (Symbol) (defaults to: nil)

    the prefix to use



26
27
28
29
30
# File 'lib/state_gate/engine/fixer.rb', line 26

def prefix(val = nil)
  _cerr(:prefix_type_err, kattr: true) unless val.is_a?(Symbol)
  _cerr(:prefix_multiple_err, kattr: true) if @prefix
  @prefix = "#{val.to_s.downcase}_"
end

#state_prefixObject

Returns the defined prefix for the state_gate, or an empty string if no prefix has been defined.

Examples:

.state_prefix   #=> 'my_prefix'
.state_prefix   #=> ''


63
64
65
# File 'lib/state_gate/engine/fixer.rb', line 63

def state_prefix
  @prefix
end

#state_suffixObject

Returns the defined suffix for the state_gate, or an empty string if no suffix has been defined.

Examples:

.state_suffix   #=> 'my_suffix'
.state_suffix   #=> ''


77
78
79
# File 'lib/state_gate/engine/fixer.rb', line 77

def state_suffix
  @suffix
end

#suffix(val = nil) ⇒ Object

A phrase to add before state names when using Class Scopes. This helps differential attributes that have similar state names.

Examples:

suffix :after  #=> Class.active_after

Parameters:

  • val (Symbol) (defaults to: nil)

    the suffix to use



43
44
45
46
47
# File 'lib/state_gate/engine/fixer.rb', line 43

def suffix(val = nil)
  _cerr(:suffix_type_err, kattr: true) unless val.is_a?(Symbol)
  _cerr(:suffix_multiple_err, kattr: true) if @suffix
  @suffix = "_#{val.to_s.downcase}"
end