Module: DeployInfo::State
- Extended by:
- State
- Included in:
- State
- Defined in:
- lib/deploy-info/state.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#state ⇒ Object
24
25
26
|
# File 'lib/deploy-info/state.rb', line 24
def state
@state
end
|
Instance Method Details
#add_state(app, user, params) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/deploy-info/state.rb', line 52
def add_state(app, user, params)
(n = {}) && (n[:name] = app)
n[:created] = DateTime.now
n[:creator] = user
%w(type).each do |opt|
n[opt.to_sym] = params[opt] if params[opt]
end
%w(protected).each do |opt|
n[opt.to_sym] = true if params[opt] && %w(true 1).any? { |x| params[opt].to_s.casecmp(x).zero? }
end
update_state(n)
find_state(node)
end
|
#delete_state(app) ⇒ Object
> Remove App from the State
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/deploy-info/state.rb', line 72
def delete_state(app)
existing = find_state(app)
return 'App not present in state' unless existing
state.delete(existing)
write_state
existing
end
|
#find_state(app) ⇒ Object
30
31
32
|
# File 'lib/deploy-info/state.rb', line 30
def find_state(app)
state.detect { |h| h[:name].casecmp(app).zero? }
end
|
#update_state(hash) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/deploy-info/state.rb', line 34
def update_state(hash)
existing = find_state(hash[:name])
if existing
state.delete(existing)
audit_string = [DateTime.now, hash[:creator]].join(' - ')
existing[:last_modified] = existing[:last_modified].is_a?(Array) ? existing[:last_modified].take(5).unshift(audit_string) : [audit_string]
hash = existing
end
state.push(hash)
write_state
end
|
#write_state ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/deploy-info/state.rb', line 84
def write_state
state.sort_by! { |h| h[:name].downcase }.uniq!
Util.write_json_config(Config.state_file, state)
end
|