Class: GrandCentral::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/grand_central/action.rb

Defined Under Namespace

Classes: DelayedDispatch

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.storeObject



36
37
38
39
40
41
42
# File 'lib/grand_central/action.rb', line 36

def self.store
  if self == Action
    @store
  else
    @store || superclass.store
  end
end

Class Method Details

.[](*args) ⇒ Object



48
49
50
# File 'lib/grand_central/action.rb', line 48

def self.[](*args)
  DelayedDispatch.new(self, store, args)
end

.call(*args) ⇒ Object



44
45
46
# File 'lib/grand_central/action.rb', line 44

def self.call(*args)
  self[*args].call
end

.create(&block) ⇒ Object



16
17
18
# File 'lib/grand_central/action.rb', line 16

def self.create &block
  with_attributes &block
end

.to_procObject



52
53
54
# File 'lib/grand_central/action.rb', line 52

def self.to_proc
  proc { |*args| call *args.flatten(1) }
end

.with_attributes(*attributes, &body) ⇒ Object



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

def self.with_attributes *attributes, &body
  klass = Class.new(self)
  klass.send :define_method, :initialize do |*args|
    attributes.each_with_index do |attribute, index|
      instance_variable_set "@#{attribute}", args[index]
    end
  end
  klass.send :attr_reader, *attributes
  klass.class_exec &body if block_given?

  klass
end

Instance Method Details

#always(&block) ⇒ Object



28
29
30
# File 'lib/grand_central/action.rb', line 28

def always &block
  promise.always &block
end

#fail(&block) ⇒ Object



24
25
26
# File 'lib/grand_central/action.rb', line 24

def fail &block
  promise.fail &block
end

#then(&block) ⇒ Object



20
21
22
# File 'lib/grand_central/action.rb', line 20

def then &block
  promise.then &block
end