Class: Stator::Alias

Inherits:
Object
  • Object
show all
Defined in:
lib/stator/alias.rb

Instance Method Summary collapse

Constructor Details

#initialize(machine, name, options = {}) ⇒ Alias

Returns a new instance of Alias.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/stator/alias.rb', line 4

def initialize(machine, name, options = {})
  @machine    = machine
  @name       = name
  @namespace  = @machine.namespace
  @full_name  = [@namespace, @name].compact.join('_')
  @states     = []
  @not        = false
  @opposite   = nil
  @constant   = options[:constant]
  @scope      = options[:scope]
end

Instance Method Details

#evaluateObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/stator/alias.rb', line 29

def evaluate
  generate_methods

  if @opposite
    op = @machine.state_alias(*@opposite)

    op.is(*@states)     if @not
    op.is_not(*@states) if !@not
  end
end

#is(*args) ⇒ Object



16
17
18
# File 'lib/stator/alias.rb', line 16

def is(*args)
  @states |= args.map(&:to_s)
end

#is_not(*args) ⇒ Object



20
21
22
23
# File 'lib/stator/alias.rb', line 20

def is_not(*args)
  @not = true
  is(*args)
end

#opposite(*args) ⇒ Object



25
26
27
# File 'lib/stator/alias.rb', line 25

def opposite(*args)
  @opposite = args
end