Class: Hookit::Resource::Base
- Inherits:
-
Object
- Object
- Hookit::Resource::Base
show all
- Defined in:
- lib/hookit/resource/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name) ⇒ Base
Returns a new instance of Base.
39
40
41
|
# File 'lib/hookit/resource/base.rb', line 39
def initialize(name)
name(name)
end
|
Instance Attribute Details
#dict ⇒ Object
Returns the value of attribute dict.
35
36
37
|
# File 'lib/hookit/resource/base.rb', line 35
def dict
@dict
end
|
Class Method Details
.actions(*actions) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/hookit/resource/base.rb', line 17
def actions(*actions)
if actions.any?
@actions = *actions
else
@actions
end
end
|
.default_action(action = nil) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/hookit/resource/base.rb', line 25
def default_action(action=nil)
if action
@default_action = action
else
@default_action || :run
end
end
|
.field(key) ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/hookit/resource/base.rb', line 7
def field(key)
define_method key do |*args, &block|
if data = block || args[0]
instance_variable_set("@#{key}", data)
else
instance_variable_get("@#{key}")
end
end
end
|
Instance Method Details
#action(*actions) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/hookit/resource/base.rb', line 60
def action(*actions)
if actions.any?
actions.each do |action|
if not self.class.actions.include? action
raise Hookit::Error::UnknownAction, "unknown action '#{action}'"
end
end
@actions = *actions
else
@actions || [default_action]
end
end
|
#can_run? ⇒ Boolean
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/hookit/resource/base.rb', line 45
def can_run?
only_if_res = true
not_if_res = false
if only_if and only_if.respond_to? :call
only_if_res = only_if.call
end
if not_if and not_if.respond_to? :call
not_if_res = not_if.call
end
only_if_res and not not_if_res
end
|
#default_action ⇒ Object
73
74
75
|
# File 'lib/hookit/resource/base.rb', line 73
def default_action
self.class.default_action
end
|
#not_if(&block) ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/hookit/resource/base.rb', line 77
def not_if(&block)
if block_given?
@not_if = block
else
@not_if
end
end
|
#only_if(&block) ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/hookit/resource/base.rb', line 85
def only_if(&block)
if block_given?
@only_if = block
else
@only_if
end
end
|
#run(action) ⇒ Object
43
|
# File 'lib/hookit/resource/base.rb', line 43
def run(action); end
|