cloudfactory 0.6 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,234 +0,0 @@
1
- require 'thor/group'
2
-
3
- module Cf # :nodoc: all
4
- class NewBadge < Thor::Group # :nodoc: all
5
- include Thor::Actions
6
- include Cf::Config
7
- source_root File.expand_path('../templates', __FILE__)
8
-
9
- def generate
10
- badge_destination = "#{Dir.pwd}/badges"
11
- FileUtils.mkdir(badge_destination)
12
- copy_file("sample-line/badge.yml", "#{badge_destination}/badge.yml")
13
- end
14
- end
15
- end
16
-
17
- module Cf # :nodoc: all
18
- class Badge < Thor
19
- include Cf::Config
20
- include Cf::BadgeYamlValidator
21
-
22
-
23
- desc "badge generate", "Generate a new badge template at badges/badge.yml"
24
- method_option :force, :type => :boolean, :default => false, :aliases => "-f", :desc => "force to overwrite the files if already exists, default is false"
25
- def generate
26
- yaml_destination = "#{Dir.pwd}/badges/badge.yml"
27
- FileUtils.rm_rf("#{Dir.pwd}/badges", :verbose => true) if options.force?
28
- if File.exist?(yaml_destination)
29
- say "Skipping #{yaml_destination} because it already exists.", :red
30
- else
31
- say "Generating a new badge template #{yaml_destination}", :green
32
- Cf::NewBadge.start()
33
- say "Badge template generated successfully.", :green
34
- say "Modify the #{yaml_destination} file and create badge with: cf badge create", :yellow
35
- end
36
- end
37
-
38
-
39
-
40
- desc "badge create", "Create badges that are in badge.yml"
41
- def create
42
- badge_source = "#{Dir.pwd}/badges"
43
- yaml_source = "#{badge_source}/badge.yml"
44
-
45
- unless File.exist?(yaml_source)
46
- say "The badge.yml file does not exist in this directory.", :red
47
- return
48
- end
49
- errors = validate(yaml_source)
50
- unless errors.present?
51
- set_target_uri(false)
52
- set_api_key(yaml_source)
53
- CF.account_name = CF::Account.info['name']
54
-
55
- badge_dump = YAML::load(File.read(yaml_source).strip)
56
- badge_dump["badge"].each do |badge_hash|
57
- name = badge_hash["name"]
58
- do_exist = CF::Badge.list(name.parameterize)
59
- if do_exist && do_exist["code"]==200
60
- say "A badge named #{name} already exists.", :yellow
61
- override = agree("Do you want to override ? [y/n] ")
62
- override == true ? badge_hash.merge!(:confirmed => true) : ((say "Badge creation aborted!", :red) and exit(1))
63
- end
64
- say "Creating badge '#{name}'"
65
- badge = CF::Badge.new(badge_hash)
66
- if badge.errors.present?
67
- say "Errors: \n", :red
68
- badge.errors.each do |error|
69
- say(error, :red)
70
- end
71
- exit(1)
72
- else
73
- say "A new badge named '#{name}' created sucessfully!"
74
- end
75
- end
76
- else
77
- say "Following errors has been encountered in your badge.yml file: #{errors}" , :red
78
- end
79
- end
80
-
81
-
82
-
83
- desc "badge update <badge_name>", "Updates the given badge within your account. Use 'cf badge update' to update all badges in badge.yml"
84
- def update(badge_name = nil)
85
- badge_source = "#{Dir.pwd}/badges"
86
- yaml_source = "#{badge_source}/badge.yml"
87
-
88
- unless File.exist?(yaml_source)
89
- say "The badge.yml file does not exist in this directory", :red
90
- return
91
- end
92
- errors = validate(yaml_source)
93
- unless errors.present?
94
- set_target_uri(false)
95
- set_api_key(yaml_source)
96
- CF.account_name = CF::Account.info['name']
97
-
98
- badge_dump = YAML::load(File.read(yaml_source).strip)
99
-
100
- badges = badge_dump["badge"]
101
-
102
- #check whether the given badge_name is present in badge.yml file and if present then take the given badge_hash for update
103
- if badge_name
104
- selected_badge = badges.select {|f| f["name"].parameterize == badge_name.parameterize }
105
- if selected_badge.present?
106
- badges = selected_badge
107
- else
108
- say "Could not find badge named '#{badge_name}' in your badge.yml file", :red
109
- exit(1)
110
- end
111
- end
112
-
113
- badges.each do |badge_hash|
114
- previous_name = badge_hash["name"]["from"] || badge_hash["name"]
115
- badge_hash["name"] = badge_hash["name"]["to"] || badge_hash["name"]
116
- do_exist = CF::Badge.list(previous_name.parameterize)
117
- #check whetether the badge do exist and has its decendents if do then retain_current_worker_badge = true so that worker and lines associated get retain if the badge get updated other wise the badge act as a new badge
118
- if do_exist && do_exist["code"]==200
119
- descendents = CF::Badge.check_for_decendents(previous_name.parameterize)
120
- if descendents
121
- say("\n!!! Warning !!!\n The badge '#{previous_name}' has the following number of tasks, lines and workers asscociated with it.\n", :yellow)
122
- badge_table = table do |t|
123
- t.headings = [ 'Tasks', 'Lines', 'Workers']
124
- t << [ descendents[:tasks], descendents[:lines_count], descendents[:workers_count]]
125
- end
126
- say(badge_table)
127
- say("\n!!! Warning !!!\n Retaining the workers will keep the workers associated with the badge.\n", :yellow)
128
- update_forcefully = agree("Do you want to retain the workers? [y/n] ")
129
- badge_hash.merge!(:retain_workers => false) if update_forcefully == false
130
- end
131
-
132
- #now update the badge
133
- say "Updating badge named '#{previous_name}'"
134
- badge = CF::Badge.update(previous_name,badge_hash)
135
- if badge && badge.code == 200
136
- say "A badge named '#{previous_name}' updated sucessfully!"
137
- else
138
- if badge.code == 422
139
- say badge["error"]["message"]
140
- else
141
- say "A badge named '#{previous_name}' can not be updated", :red
142
- end
143
- exit(1)
144
- end
145
- else
146
- say "A badge named '#{previous_name}' does not exist!", :red
147
- exit(1)
148
- end
149
- end
150
- else
151
- say "Following errors has been encountered in your badge.yml file: #{errors}" , :red
152
- end
153
- end
154
-
155
-
156
-
157
- desc "badge delete <badge name>", "Delete the given badge within your account"
158
- method_option :force, :type => :boolean, :aliases => "-f", :default => false, :desc => "force delete the badge"
159
- def delete(name = nil)
160
- #set badge basic credentials
161
- line_source = Dir.pwd
162
- yaml_source = "#{line_source}/line.yml"
163
- set_target_uri(false)
164
- set_api_key(yaml_source)
165
- set_target_uri(false)
166
- CF.account_name = CF::Account.info['name']
167
-
168
- #list all badges if name is not present else list the specific badge
169
- if name
170
- badge_decendents = CF::Badge.check_for_decendents(name)
171
- if badge_decendents
172
- say("\n!!! Warning !!!\n The badge #{name} has following number of tasks, lines and workers asscociated with it.\n", :yellow)
173
- badge_table = table do |t|
174
- t.headings = [ 'Tasks', 'Lines', 'Workers']
175
- t << [ badge_decendents[:tasks], badge_decendents[:lines_count], badge_decendents[:workers_count]]
176
- end
177
- say(badge_table)
178
-
179
- delete_forcefully = agree("Do you still want to delete this badge? [y/n] ")
180
- if delete_forcefully
181
- badge_resp = CF::Badge.destroy(name,options.merge(:force => true))
182
- else
183
- say "Badge deletion aborted!", :yellow
184
- exit(1)
185
- end
186
- else
187
- say "Deleting badge named '#{name}'"
188
- badge_resp = CF::Badge.destroy(name)
189
- end
190
- badge_resp["code"] == 200 ? (say "A badge named #{name} deleted sucessfully!", :green) : (say badge_resp["error"]["message"], :red)
191
- else
192
- say "Name of the badge for deletion is missing.", :red
193
- end
194
- end
195
-
196
-
197
-
198
- desc "badge list ", "List all badges asscociated with your account. Use 'cf badge list <badge_name>' for single badge"
199
- def list(name = nil)
200
- #set badge basic credentials
201
- line_source = Dir.pwd
202
- yaml_source = "#{line_source}/line.yml"
203
- set_target_uri(false)
204
- set_api_key(yaml_source)
205
- set_target_uri(false)
206
- CF.account_name = CF::Account.info['name']
207
-
208
- #list all badges if name is not present else list the specific badge
209
- if name
210
- badge_resp = CF::Badge.list(name)
211
- else
212
- badge_resp = CF::Badge.list
213
- end
214
-
215
- #show list of badges in the tabular view
216
- if badges = badge_resp["badges"]
217
- say "Listing badges within your account" , :green
218
- badges.sort! { |a, b| a['name'] <=> b['name'] }
219
- badge_table = table do |t|
220
- t.headings = ["Name", 'Number oF Tasks', 'Lines Associates', 'Workers', 'description']
221
- badges.each do |badge|
222
- badge = Hashie::Mash.new(badge)
223
- t << [badge.name, badge.num_of_tasks, badge.line_associated, badge.workers, badge.description]
224
- end
225
- end
226
- say(badge_table)
227
- else
228
- say badge_resp["error"]["message"], :red
229
- end
230
- end
231
-
232
-
233
- end
234
- end
@@ -1,25 +0,0 @@
1
- require 'pry'
2
- module Cf
3
- module BadgeYamlValidator
4
-
5
- def validate(yaml_path)
6
- errors = []
7
- badge_dump = YAML::load(File.read(yaml_path).strip)
8
- if badge_dump.class == Hash
9
- if badge_dump["badge"].class == Array
10
- badge_dump["badge"].each do |badge|
11
- errors << "form for the badge is missing" unless badge["form"]
12
- errors << "name of the badge is missing" unless badge["name"]
13
- errors << "description for the badge is missing" unless badge["description"]
14
- errors << "known answers for the badge must be array of hashes" unless badge["known_answers"].class == Array
15
- end
16
- else
17
- errors << "badge mut be array of hash"
18
- end
19
- else
20
- errors << "badges must be hash"
21
- end
22
- errors
23
- end
24
- end
25
- end
@@ -1,21 +0,0 @@
1
- badge:
2
- - name: Designer #name of the badge that you want to create
3
- description: This badge allow to do the designing tasks #description of the badge
4
- max_badge_assignments: 5 #numbers of worker who can take the badge
5
- retries_allowed: 5 #number of retries that worker get at the time of taking the badge
6
- pass_percentage: 80 #the value in percentage that the worker must score to pass the test
7
- assignment_duration: 3600 #time assigned for badge test
8
- check_manually: false #checking badge answers that worker has ssubmitted
9
- allow_retake_after: 30 #number of day after which the worker can again take the badge exam
10
- form: badge_form.html #form for the badge. It should be html format if it is a custom form
11
- known_answers: #the hash of question and answers for the badge
12
- - input:
13
- image_url: http://www.crystalinks.com/newton.jpg
14
- expected_output:
15
- gender: male
16
- age: 60
17
- - input:
18
- image_url: http://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Salmanrampwalk.png/220px-Salmanrampwalk.png
19
- expected_output:
20
- gender: male
21
- age: 50