Module: Hookit::Hook
- Defined in:
- lib/hookit/hook.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *args, &block) ⇒ Object
awesome resource-backed dsl
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/hookit/hook.rb', line 78
def method_missing(method_symbol, *args, &block)
resource_klass = Hookit.resources.get(method_symbol)
if resource_klass
resource = resource_klass.new(*args)
resource.dict = dict
resource.instance_eval(&block) if block_given?
if resource.can_run?
actions = resource.action
if actions.length > 1
res = {}
actions.each do |action|
res[action] = resource.run action
end
res
else
resource.run actions.first
end
end
else
super
end
end
|
Instance Method Details
#converge(map, list) ⇒ Object
#db ⇒ Object
31
32
33
|
# File 'lib/hookit/hook.rb', line 31
def db
@db ||= Hookit::DB.new
end
|
67
68
69
70
71
72
73
74
75
|
# File 'lib/hookit/hook.rb', line 67
def detect_platform
Hookit.platforms.each do |key, value|
platform = value.new
if platform.detect?
return platform
end
end
false
end
|
#dict ⇒ Object
35
36
37
|
# File 'lib/hookit/hook.rb', line 35
def dict
@dict ||= {}
end
|
#get(key) ⇒ Object
43
44
45
|
# File 'lib/hookit/hook.rb', line 43
def get(key)
dict[key]
end
|
#log(level, message) ⇒ Object
47
48
49
|
# File 'lib/hookit/hook.rb', line 47
def log(level, message)
logger.log level, message
end
|
#logger ⇒ Object
51
52
53
|
# File 'lib/hookit/hook.rb', line 51
def logger
@logger ||= Hookit::Logger.new(get(:logfile), get(:log_level))
end
|
#logvac ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/hookit/hook.rb', line 55
def logvac
@logvac ||= Hookit::Logvac.new({
app: payload[:app][:id],
token: payload[:app][:logvac_token],
deploy: payload[:deploy][:id]
})
end
|
#parse_payload ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/hookit/hook.rb', line 11
def parse_payload
if not ARGV.empty?
MultiJson.load ARGV.first, symbolize_keys: true
else
{}
end
end
|
#payload ⇒ Object
7
8
9
|
# File 'lib/hookit/hook.rb', line 7
def payload
@payload ||= parse_payload
end
|
63
64
65
|
# File 'lib/hookit/hook.rb', line 63
def platform
@platform ||= detect_platform
end
|
#registry(key, value = nil) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/hookit/hook.rb', line 23
def registry(key, value=nil)
unless value.nil?
db.put(key, value)
else
db.fetch(key)
end
end
|
#set(key, value) ⇒ Object
39
40
41
|
# File 'lib/hookit/hook.rb', line 39
def set(key, value)
dict[key] = value
end
|