Class: AngryMob::Act

Inherits:
Object show all
Defined in:
lib/angry_mob/act.rb,
lib/angry_mob/act/scheduler.rb

Overview

A ‘Builder::Act` groups target calls.

Defined Under Namespace

Classes: Scheduler

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, multi, &blk) ⇒ Act



8
9
10
11
12
# File 'lib/angry_mob/act.rb', line 8

def initialize(name,multi,&blk)
  @name = name
  @multi = multi
  @blk = blk
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(nickname, *args, &blk) ⇒ Object

TODO - de-mm



52
53
54
55
# File 'lib/angry_mob/act.rb', line 52

def method_missing(nickname,*args,&blk)
  return super unless @running
  __run_target(nickname,*args,&blk)
end

Instance Attribute Details

#definition_fileObject (readonly)

Returns the value of attribute definition_file.



6
7
8
# File 'lib/angry_mob/act.rb', line 6

def definition_file
  @definition_file
end

#mobObject (readonly)

Returns the value of attribute mob.



6
7
8
# File 'lib/angry_mob/act.rb', line 6

def mob
  @mob
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/angry_mob/act.rb', line 6

def name
  @name
end

Class Method Details

.synthesise(mob, name, &blk) ⇒ Object



27
28
29
30
31
# File 'lib/angry_mob/act.rb', line 27

def self.synthesise(mob,name,&blk)
  act = new(name,true,&blk)
  act.bind(mob,"name")
  act.run!
end

Instance Method Details

#__run_target(nickname, *args, &blk) ⇒ Object

Schedules a target, adding call-location context along the way.



58
59
60
61
62
63
64
65
# File 'lib/angry_mob/act.rb', line 58

def __run_target(nickname,*args,&blk)
  call = mob.target_mother.target_call(nickname,*args,&blk)

  call.merge_defaults(defaults.defaults_for(nickname))
  call.call(self)

  call.target
end

#act_now(act_name, *args) ⇒ Object



98
99
100
# File 'lib/angry_mob/act.rb', line 98

def act_now act_name, *args
  mob.act_scheduler.act_now(act_name,*args)
end

#bind(mob, file) ⇒ Object

Binds the act to the mob and the file from which it came.



20
21
22
23
24
25
# File 'lib/angry_mob/act.rb', line 20

def bind(mob,file)
  @mob  = mob
  @definition_file = file

  mob.act_scheduler.add_act @name, self
end

#defaultsObject

Definition helpers



75
76
77
# File 'lib/angry_mob/act.rb', line 75

def defaults
  @defaults ||= Target::Defaults.new
end

#gem(*args, &blk) ⇒ Object

bundler + rubygems clusterfuck



47
48
49
# File 'lib/angry_mob/act.rb', line 47

def gem(*args,&blk)
  __run_target(:gem,*args,&blk)
end

#in_sub_act(*args, &blk) ⇒ Object



67
68
69
70
71
# File 'lib/angry_mob/act.rb', line 67

def in_sub_act(*args,&blk)
  sub_act = self.class.new("#{name}-sub-act",true,&blk)
  sub_act.bind(@mob,@definition_file)
  sub_act.run!(*args)
end

#laterObject

directly schedule a call on the delayed list



88
89
90
91
92
# File 'lib/angry_mob/act.rb', line 88

def later
  n = Target::Notify.new(self)
  mob.notifier.schedule_notification n
  n
end

#log(message) ⇒ Object



15
# File 'lib/angry_mob/act.rb', line 15

def log(message); mob.ui.log message end

#multi?Boolean



17
# File 'lib/angry_mob/act.rb', line 17

def multi?; !!@multi end

#nodeObject



94
95
96
# File 'lib/angry_mob/act.rb', line 94

def node
  mob.node
end

#notificationsObject



83
84
85
# File 'lib/angry_mob/act.rb', line 83

def notifications
  mob.notifier
end

#notifyObject



79
80
81
# File 'lib/angry_mob/act.rb', line 79

def notify
  Target::Notify.new(self)
end

#run!(*arguments) ⇒ Object

Executes the block via ‘instance_exec`



36
37
38
39
40
41
42
43
44
# File 'lib/angry_mob/act.rb', line 36

def run!(*arguments)
  ui.push("act '#{name}'", :bubble => true) do
    @running = true

    instance_exec *arguments, &@blk

    @running = false
  end
end

#schedule_act(act_name) ⇒ Object



102
103
104
# File 'lib/angry_mob/act.rb', line 102

def schedule_act act_name
  mob.act_scheduler.schedule_act(act_name)
end

#schedule_acts_matching(regex, &block) ⇒ Object



106
107
108
# File 'lib/angry_mob/act.rb', line 106

def schedule_acts_matching(regex,&block)
  mob.act_scheduler.schedule_acts_matching(regex,&block)
end

#uiObject



14
# File 'lib/angry_mob/act.rb', line 14

def ui; mob.ui end