Class: Ubalo::Pod
- Inherits:
-
Object
show all
- Includes:
- Util
- Defined in:
- lib/ubalo/pod.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util
append_config, columns, debug_mode?, decode_content, get_targz, indent, login_suggestion, normalize_pod_name, pluralize, put_targz, read_config, time_ago_in_words, write_config
Constructor Details
#initialize(account, username, name, attributes) ⇒ Pod
Returns a new instance of Pod.
11
12
13
14
15
16
|
# File 'lib/ubalo/pod.rb', line 11
def initialize(account, username, name, attributes)
@account = account
@username = username
@name = name
update_attributes(attributes)
end
|
Instance Attribute Details
#archive ⇒ Object
Returns the value of attribute archive.
9
10
11
|
# File 'lib/ubalo/pod.rb', line 9
def archive
@archive
end
|
#code_updated_at ⇒ Object
Returns the value of attribute code_updated_at.
9
10
11
|
# File 'lib/ubalo/pod.rb', line 9
def code_updated_at
@code_updated_at
end
|
#compilation_process ⇒ Object
Returns the value of attribute compilation_process.
9
10
11
|
# File 'lib/ubalo/pod.rb', line 9
def compilation_process
@compilation_process
end
|
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/ubalo/pod.rb', line 9
def name
@name
end
|
#state ⇒ Object
Returns the value of attribute state.
9
10
11
|
# File 'lib/ubalo/pod.rb', line 9
def state
@state
end
|
#username ⇒ Object
Returns the value of attribute username.
9
10
11
|
# File 'lib/ubalo/pod.rb', line 9
def username
@username
end
|
Class Method Details
.create_with_json(account, json) ⇒ Object
5
6
7
|
# File 'lib/ubalo/pod.rb', line 5
def self.create_with_json(account, json)
new(account, json.fetch('user').fetch('username'), json.fetch('name'), json)
end
|
Instance Method Details
#==(other) ⇒ Object
152
153
154
|
# File 'lib/ubalo/pod.rb', line 152
def ==(other)
fullname == other.fullname
end
|
#clone_to(pod_dir) ⇒ Object
114
115
116
117
118
|
# File 'lib/ubalo/pod.rb', line 114
def clone_to(pod_dir)
refresh!
archive.(pod_dir)
pod_dir.write_name(fullname)
end
|
#compiled? ⇒ Boolean
120
121
122
|
# File 'lib/ubalo/pod.rb', line 120
def compiled?
state == 'compiled'
end
|
#delete! ⇒ Object
124
125
126
127
|
# File 'lib/ubalo/pod.rb', line 124
def delete!
request(:delete, nil, :parse => false)
@deleted = true
end
|
#deleted? ⇒ Boolean
129
130
131
|
# File 'lib/ubalo/pod.rb', line 129
def deleted?
!!@deleted
end
|
#full_printable_result ⇒ Object
140
141
142
143
144
145
146
|
# File 'lib/ubalo/pod.rb', line 140
def full_printable_result
s = printable_result
if compilation_process
s << compilation_process.printable_result
end
s
end
|
#fullname ⇒ Object
30
31
32
|
# File 'lib/ubalo/pod.rb', line 30
def fullname
"#{@username}/#{@name}"
end
|
#inspect ⇒ Object
148
149
150
|
# File 'lib/ubalo/pod.rb', line 148
def inspect
"#<Pod #{fullname.inspect} state=#{state.inspect}>"
end
|
#latest_task ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/ubalo/pod.rb', line 66
def latest_task
if task_json = request(:get, "/tasks/latest")
@account.task_from_json(task_json)
else
raise Ubalo::Error, "Could not find latest task for #{fullname.inspect}"
end
end
|
#printable_result ⇒ Object
133
134
135
136
137
138
|
# File 'lib/ubalo/pod.rb', line 133
def printable_result
s = ""
s << " name: #{fullname}\n"
s << " state: #{state}\n"
s
end
|
#push_from(pod_dir, detached = false) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/ubalo/pod.rb', line 74
def push_from(pod_dir, detached=false)
tailer = Ubalo::TimedTailer.new(logger)
tailer.update("Pushing files to #{fullname}...")
pod_dir.assert_not_empty!
update!
new_archive.activate_from(pod_dir)
logger.poll do
tailer.update("Pushed files. Waiting to build #{fullname}...")
refresh!
return if detached
compilation_process
end
compilation_process.tail(tailer, "Pushed files. Building #{fullname}...") do
refresh!
compiled?
end
tailer.update("Pushed #{fullname}. Exit code: #{compilation_process.exit_result}.\n")
end
|
#refresh! ⇒ Object
24
25
26
27
28
|
# File 'lib/ubalo/pod.rb', line 24
def refresh!
update_attributes(request(:get))
rescue RestClient::ResourceNotFound
raise Ubalo::Error, "Could not find pod #{fullname.inspect}"
end
|
#run(argv, arg) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/ubalo/pod.rb', line 40
def run(argv, arg)
if argv && argv.empty?
raise Ubalo::Error, "Specify the command to run"
end
params = {}
if arg
params.merge!(
:arg_content_type => UbaloJSON.content_type,
:arg => UbaloJSON.dump(arg)
)
end
if argv
params.merge!(:argv => argv)
end
task = @account.task_from_json(request(:post, "/tasks", :params => params))
task
rescue RestClient::Conflict
raise Ubalo::Error, "Cannot run pod while compiling"
rescue RestClient::ResourceNotFound
raise Ubalo::Error, "Pod not found"
end
|
#stop! ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/ubalo/pod.rb', line 99
def stop!
tailer = Ubalo::TimedTailer.new(logger)
tailer.update("Stopping #{fullname}...")
request(:put, "/stop")
logger.poll do
tailer.update("Stopping #{fullname}...")
refresh!
compiled?
end
tailer.update("Stopped #{fullname}. Compilation exit code: #{compilation_process.exit_result}.\n")
end
|
#tasks ⇒ Object
34
35
36
37
38
|
# File 'lib/ubalo/pod.rb', line 34
def tasks
request(:get, "/tasks").map do |task_json|
@account.task_from_json(task_json)
end
end
|
#update! ⇒ Object
18
19
20
21
22
|
# File 'lib/ubalo/pod.rb', line 18
def update!
update_attributes(request(:put))
rescue RestClient::ResourceNotFound
raise Ubalo::Error, "Could not update pod #{fullname.inspect}"
end
|
#url ⇒ Object
156
157
158
|
# File 'lib/ubalo/pod.rb', line 156
def url
@account.url_for(path_prefix)
end
|