Module: Abid::PlayCore

Included in:
MixinTask::Mixin, Play
Defined in:
lib/abid/play_core.rb

Instance Method Summary collapse

Instance Method Details

#include(*mod) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/abid/play_core.rb', line 32

def include(*mod)
  ms = mod.map do |m|
    if m.is_a? Module
      m
    else
      mixin_task = task.application[m, task.scope]

      fail "#{m} is not a mixin" unless mixin_task.is_a? MixinTask

      mixin_task.mixin.tap do |mixin|
        # inherit params_spec
        mixin.params_spec.each do |k, v|
          params_spec[k] ||= v
        end
      end
    end
  end

  super(*ms)
end

#param(name, **param_spec) ⇒ Object



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

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

#params_specObject



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

def params_spec
  @params_spec ||= {}
end

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



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/abid/play_core.rb', line 3

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

#undef_param(name) ⇒ Object



27
28
29
30
# File 'lib/abid/play_core.rb', line 27

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