Class: Abid::Play

Inherits:
Object
  • Object
show all
Defined in:
lib/abid/play.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ Play

Returns a new instance of Play.



82
83
84
# File 'lib/abid/play.rb', line 82

def initialize(task)
  @task = task
end

Class Attribute Details

.taskObject

Returns the value of attribute task.



6
7
8
# File 'lib/abid/play.rb', line 6

def task
  @task
end

Instance Attribute Details

#taskObject (readonly)

Returns the value of attribute task.



80
81
82
# File 'lib/abid/play.rb', line 80

def task
  @task
end

Class Method Details

.after(&block) ⇒ Object



64
65
66
# File 'lib/abid/play.rb', line 64

def after(&block)
  hooks[:after] << block
end

.around(&block) ⇒ Object



68
69
70
# File 'lib/abid/play.rb', line 68

def around(&block)
  hooks[:around] << block
end

.before(&block) ⇒ Object



60
61
62
# File 'lib/abid/play.rb', line 60

def before(&block)
  hooks[:before] << block
end

.helpers(*extensions, &block) ⇒ Object



51
52
53
54
# File 'lib/abid/play.rb', line 51

def helpers(*extensions, &block)
  class_eval(&block) if block_given?
  include(*extensions) if extensions.any?
end

.hooksObject



27
28
29
30
31
32
33
34
# File 'lib/abid/play.rb', line 27

def hooks
  @hooks ||= {
    setup: [],
    before: [],
    after: [],
    around: []
  }
end

.inherited(child) ⇒ Object



8
9
10
11
# File 'lib/abid/play.rb', line 8

def inherited(child)
  params_spec.each { |k, v| child.params_spec[k] = v.dup }
  hooks.each { |k, v| child.hooks[k] = v.dup }
end

.method_added(name) ⇒ Object



72
73
74
# File 'lib/abid/play.rb', line 72

def method_added(name)
  params_spec.delete(name) # undef param
end

.param(name, **param_spec) ⇒ Object



17
18
19
20
# File 'lib/abid/play.rb', line 17

def param(name, **param_spec)
  define_method(name) { task.params[name] }
  params_spec[name] = { significant: true }.merge(param_spec)
end

.params_specObject



13
14
15
# File 'lib/abid/play.rb', line 13

def params_spec
  @params_spec ||= {}
end

.set(name, value = nil, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/abid/play.rb', line 36

def set(name, value = nil, &block)
  var = :"@#{name}"

  define_method(name) do
    unless instance_variable_defined?(var)
      if !value.nil?
        instance_variable_set(var, value)
      elsif block_given?
        instance_variable_set(var, instance_eval(&block))
      end
    end
    instance_variable_get(var)
  end
end

.setup(&block) ⇒ Object



56
57
58
# File 'lib/abid/play.rb', line 56

def setup(&block)
  hooks[:setup] << block
end

.undef_param(name) ⇒ Object



22
23
24
25
# File 'lib/abid/play.rb', line 22

def undef_param(name)
  params_spec.delete(name)
  undef_method(name) if method_defined?(name)
end

Instance Method Details

#needs(task_name, **params) ⇒ Object



90
91
92
# File 'lib/abid/play.rb', line 90

def needs(task_name, **params)
  task.enhance([[task_name, params]])
end

#preview?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/abid/play.rb', line 98

def preview?
  task.application.options.preview
end

#runObject



86
87
88
# File 'lib/abid/play.rb', line 86

def run
  # noop
end

#volatile?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/abid/play.rb', line 94

def volatile?
  volatile
end