Class: Gexp::Handler::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/gexp/handler/transition.rb,
lib/gexp/handler/transition/builder.rb

Direct Known Subclasses

Builder

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transition, object = nil, subject = nil, provider = nil) ⇒ Transition

Note:

Выбор конечного объекта определяется конфигом object

Returns a new instance of Transition.



21
22
23
24
25
26
27
28
29
30
# File 'lib/gexp/handler/transition.rb', line 21

def initialize(transition, object = nil, subject = nil, provider = nil)
  @transition = transition
  actor       = @transition.args.first

  unless self.actor_support?(actor)
    raise "Unsupported actor type #{@actor.class.name}"
  else
    @actor = actor
  end
end

Instance Attribute Details

#objectObject

Returns the value of attribute object.



5
6
7
# File 'lib/gexp/handler/transition.rb', line 5

def object
  @object
end

#providerObject

Returns the value of attribute provider.



5
6
7
# File 'lib/gexp/handler/transition.rb', line 5

def provider
  @provider
end

#subjectObject

Returns the value of attribute subject.



5
6
7
# File 'lib/gexp/handler/transition.rb', line 5

def subject
  @subject
end

#transitionObject

Returns the value of attribute transition.



5
6
7
# File 'lib/gexp/handler/transition.rb', line 5

def transition
  @transition
end

Class Method Details

.namespacesObject



7
8
9
10
11
12
# File 'lib/gexp/handler/transition.rb', line 7

def self.namespaces
  @namespaces ||= {
    checkers:  Gexp::Handler::Check,
    modifiers: Gexp::Handler::Modify,
  }
end

Instance Method Details

#actor_support?(actor) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/gexp/handler/transition.rb', line 48

def actor_support?(actor)
  !actor.nil?
end

#configObject



44
45
46
# File 'lib/gexp/handler/transition.rb', line 44

def config
  @config   ||= self.object.config
end

#handlers(type = nil) ⇒ Array(Gexp::Handler)

Возвращает массив обработчиков

Returns:



63
64
65
66
67
68
# File 'lib/gexp/handler/transition.rb', line 63

def handlers(type = nil)
  type ||= :checkers
  (self.send(type) || []).map do |handler_params|
    self.produce(handler_params, type)
  end
end

#produce(params, type) ⇒ Object

Создает объект обработчика



55
56
57
58
# File 'lib/gexp/handler/transition.rb', line 55

def produce(params, type)
  producer = Gexp::Handler::Producer.new params, type
  producer.emit
end