Class: AngryMob::Target

Inherits:
Object show all
Includes:
Tracking
Defined in:
lib/angry_mob/target.rb,
lib/angry_mob/target/call.rb,
lib/angry_mob/target/mother.rb,
lib/angry_mob/target/notify.rb,
lib/angry_mob/target/defaults.rb,
lib/angry_mob/target/tracking.rb,
lib/angry_mob/target/arguments.rb,
lib/angry_mob/target/default_resource_locator.rb

Defined Under Namespace

Modules: Tracking Classes: Arguments, Call, DefaultResourceLocator, Defaults, Mother, Notify

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Tracking

included, register_klass_file, subclass_files, subclasses

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object (protected)

delegate to the default object



249
250
251
252
253
254
255
# File 'lib/angry_mob/target.rb', line 249

def method_missing(method,*args,&blk)
  if (dobj = default_object) && dobj.respond_to?(method)
    dobj.send(method,*args,&blk)
  else
    super
  end
end

Instance Attribute Details

#actObject

Returns the value of attribute act.



66
67
68
# File 'lib/angry_mob/target.rb', line 66

def act
  @act
end

#argsObject (readonly)

Returns the value of attribute args.



65
66
67
# File 'lib/angry_mob/target.rb', line 65

def args
  @args
end

#current_actionObject (readonly)

Returns the value of attribute current_action.



65
66
67
# File 'lib/angry_mob/target.rb', line 65

def current_action
  @current_action
end

Class Method Details

.actionsObject



22
23
24
# File 'lib/angry_mob/target.rb', line 22

def actions
  @actions ||= ['nothing']
end

.all_actionsObject



25
26
27
28
# File 'lib/angry_mob/target.rb', line 25

def all_actions
  @all_actions ||= from_superclass(:all_actions, ['nothing'])
  @all_actions |= actions
end

.default_actionObject



18
19
20
# File 'lib/angry_mob/target.rb', line 18

def default_action
  @set_default_action = true
end

.default_action_nameObject



30
31
32
# File 'lib/angry_mob/target.rb', line 30

def default_action_name
  @default_action
end

.instance_key(args) ⇒ Object

Based on the args, makes a unique key for a target instance. This could be overridden by subclasses.



37
38
39
# File 'lib/angry_mob/target.rb', line 37

def instance_key(args)
  args.key
end

Instance Method Details

#changed?Boolean

Has the state changed?

dir("/tmp/config").changed? && sh("echo it changed")

Returns:

  • (Boolean)


135
136
137
# File 'lib/angry_mob/target.rb', line 135

def changed?
  state_changed?
end

#mobObject



68
# File 'lib/angry_mob/target.rb', line 68

def mob; act.mob end

#nicknameObject

class << self



61
62
63
# File 'lib/angry_mob/target.rb', line 61

def nickname
  self.class.nickname
end

#nothingObject

nothing actions are no-ops but by being called, prevent the default action being called



76
77
78
# File 'lib/angry_mob/target.rb', line 76

def nothing(*)
  false
end

#noticing_changes(args, &blk) ⇒ Object

Executes actions with full context and all the trimmings.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/angry_mob/target.rb', line 92

def noticing_changes(args,&blk)
  reset!
  @args = args

  ui.push(to_s) do
    do_validation!

    before_state
    before_call if respond_to?(:before_call)

    ui.debug "before_state=#{before_state.inspect}"

    if skip?
      ui.skipped! "skipping"
      return
    end

    # Here's the core of the target:
    if node.dry_run?
      ui.skipped! "DRY RUN: skipping action"
      return
    else
      # riiight here:
      yield
    end

    ui.debug "after_state=#{state.inspect}"

    # If the state's changed, let it be known
    if state_changed?
      changed 
      notify
      ui.ok!
    else
      ui.skipped! "target didn't change"
    end
  
  end
  self
end

#to_sObject

Definition-time helpers



82
83
84
85
86
87
88
# File 'lib/angry_mob/target.rb', line 82

def to_s
  if default_object
    "#{nickname}(#{default_object})"
  else
    "#{nickname}()"
  end
end

#uiObject



69
# File 'lib/angry_mob/target.rb', line 69

def ui ; mob.ui  end