fox 0.0.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +196 -14
  3. data/bin/fox +28 -8
  4. data/fox.gemspec +41 -3
  5. data/lib/fox.rb +23 -10
  6. data/lib/fox/cli.rb +17 -0
  7. data/lib/fox/configuration.rb +48 -0
  8. data/lib/fox/core_ext.rb +8 -0
  9. data/lib/fox/core_ext/array.rb +51 -0
  10. data/lib/fox/core_ext/hash.rb +17 -0
  11. data/lib/fox/core_ext/io_binary_read.rb +20 -0
  12. data/lib/fox/error.rb +8 -0
  13. data/lib/fox/error/errors.rb +232 -0
  14. data/lib/fox/interface/thor/all.rb +34 -0
  15. data/lib/fox/interface/thor/configuration.rb +71 -0
  16. data/lib/fox/interface/thor/create.rb +49 -0
  17. data/lib/fox/interface/thor/default.rb +67 -0
  18. data/lib/fox/interface/thor/init.rb +57 -0
  19. data/lib/fox/interface/thor/mixin/config_choice.rb +3 -3
  20. data/lib/fox/interface/thor/mixin/configuration.rb +1 -1
  21. data/lib/fox/interface/thor/mixin/database.rb +129 -0
  22. data/lib/fox/interface/thor/mixin/default.rb +6 -0
  23. data/lib/fox/interface/thor/mixin/default_model.rb +13 -0
  24. data/lib/fox/interface/thor/mixin/generators/base_generator.rb +35 -0
  25. data/lib/fox/interface/thor/mixin/generators/structure.rb +41 -0
  26. data/lib/fox/interface/thor/mixin/generators/template_loader.rb +48 -0
  27. data/lib/fox/interface/thor/mixin/history.rb +12 -0
  28. data/lib/fox/interface/thor/mixin/logger.rb +2 -2
  29. data/lib/fox/interface/thor/mixin/model.rb +19 -0
  30. data/lib/fox/interface/thor/new.thor +74 -0
  31. data/lib/fox/interface/thor/version.rb +59 -0
  32. data/lib/fox/library/choice.rb +160 -0
  33. data/lib/fox/library/logger.rb +175 -0
  34. data/lib/fox/library/project_builder.rb +83 -0
  35. data/lib/fox/library/secure_config.rb +114 -0
  36. metadata +298 -7
  37. data/lib/fox/interface/thor/version.thor +0 -33
@@ -0,0 +1,83 @@
1
+ #! /usr/bin/env ruby
2
+
3
+
4
+ # System
5
+ require 'thor'
6
+ require 'andand'
7
+ require 'fileutils'
8
+
9
+
10
+
11
+ class ProjectBuilder
12
+
13
+ attr_reader :name
14
+
15
+ TEMPLATES = {
16
+ :exe =>
17
+ <<-EOT
18
+ #!/usr/bin/ruby -w
19
+
20
+ require 'rubygems'
21
+ require 'commandline
22
+ require '%name%'
23
+
24
+ class %name.capitalize%App < CommandLine::Application
25
+ def initialize
26
+ end
27
+
28
+ def main
29
+ end
30
+ end#class %name.capitalize%App
31
+ EOT
32
+ }
33
+
34
+ def initialize name
35
+ @name = name
36
+ @top_level_dir = Dir.pwd
37
+ @project_dir = File.join(@top_level_dir, @name)
38
+
39
+ FileUtils.mkdir_p( @project_dir )
40
+
41
+ @cwd = @project_dir
42
+ end
43
+
44
+ def create_project
45
+ yield
46
+ end # of def create_project }}}
47
+
48
+ def self.load project_name, dsl
49
+ proj = new( project_name )
50
+ proj = proj.instance_eval( File.read(dsl), dsl )
51
+ proj
52
+ end # of def self.load }}}
53
+
54
+ def dir dir_name
55
+ old_cwd = @cwd
56
+ @cwd = File.join(@cwd, dir_name)
57
+ FileUtils.mkdir_p(@cwd)
58
+ yield self if block_given?
59
+ ensure
60
+ @cwd = old_cwd
61
+ end # of def dir }}}
62
+
63
+ def touch *file_names
64
+ file_names.flatten.each do |file|
65
+ FileUtils.touch( File.join(@cwd, "#{file}") )
66
+ end
67
+ end # of def touch }}}
68
+
69
+ # def create_rb_file(file_names)
70
+ # file_names.each { |file| touch(file + ".rb") }
71
+ # end
72
+
73
+ # def create_from_template(template_id, filename)
74
+ # File.open(File.join(@cwd, filename), "w+") { |f|
75
+ # str = TEMPLATES[template_id]
76
+ # str.gsub!(/%[^%]+%/) { |m| instance_eval m[1..-2] }
77
+ # f.puts str
78
+ # }
79
+ # end
80
+
81
+ end # of class ProjectBuilder
82
+
83
+ # vim:ts=2:tw=100:wm=100:syntax=ruby
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # System includes
5
+ require 'secure_yaml'
6
+
7
+
8
+ # @class class SecureConfig
9
+ # @brief Handles secure configs
10
+ class SecureConfig
11
+
12
+ # @fn def initialize filename, mode = :standard # {{{
13
+ # @brief Default constructor for SecureConfig
14
+ #
15
+ # @param [String] filename Valid filename of a file we want to decrypt
16
+ # @param [Symbol] mode Default mode for SecureConfig
17
+ def initialize filename, mode = :standard
18
+
19
+ sane = check_sanity( filename )
20
+ type = detect_type( filename )
21
+
22
+ if mode == :standard
23
+ if( type == :yaml )
24
+ @contents = decrypt_yaml( filename )
25
+ else
26
+ raise NotImplementedError, "Don't know how to handle that file type (#{type.to_s})"
27
+ end
28
+
29
+ end # of if mode ==
30
+
31
+ end # }}}
32
+
33
+ # @fn def check_sanity filename # {{{
34
+ # @brief Performs various checks on the file to ensure sanity
35
+ #
36
+ # @param [String] filename Valid filename of a file we want to decrypt
37
+ # @param [Boolean] strict Strict checking, if enabled will terminate app if not correct
38
+ #
39
+ # @return [Boolean] True, if sane, false if soemthing is wrong
40
+ def check_sanity filename, strict = true
41
+
42
+ result = false
43
+
44
+ raise ArgumentError, "File is not a file but a directory" if( File.directory?( filename ) )
45
+ raise ArgumentError, "File is a socket" if( File.socket?( filename ) )
46
+
47
+ raise ArgumentError, "File is not readable" unless( File.readable?( filename ) )
48
+ raise ArgumentError, "File does not exist" unless( File.exists?( filename ) )
49
+ raise ArgumentError, "File is empty" if( File.zero?( filename ) )
50
+
51
+ if( strict )
52
+ raise ArgumentError, "ENV[ 'PROPERTIES_ENCRYPTION_PASSWORD' ] missing - fatal error" if( ENV[ "PROPERTIES_ENCRYPTION_PASSWORD" ].nil? )
53
+ else
54
+ puts "(WW) Assuming empty PROPERTIES_ENCRYPTION_PASSWORD ! Decryption of secure yaml will fail !"
55
+ ENV[ "PROPERTIES_ENCRYPTION_PASSWORD" ] = ""
56
+ end
57
+
58
+
59
+
60
+ result = true
61
+
62
+ return result
63
+ end # }}}
64
+
65
+ # @fn def detect_type filename = @filename # {{{
66
+ # @brief Detects file type
67
+ #
68
+ # @param [String] filename Valid filename of a file we want to decrypt
69
+ #
70
+ # @return [Function]
71
+ def detect_type filename = @filename
72
+
73
+ filename = File.basename( filename )
74
+
75
+ # sometimes files end in .yaml.encrypted
76
+ filename.gsub!( ".encrypted", "" )
77
+ extension = filename.split( "." ).last
78
+ response = nil
79
+
80
+ raise ArgumentError, "Error in guessing file type" if( extension.empty? )
81
+
82
+ case extension
83
+ when "yaml"
84
+ response = :yaml
85
+ else
86
+ raise NotImplementedError, "Couldn't detect file type correctly"
87
+ end
88
+
89
+ return response
90
+ end # }}}
91
+
92
+ # @fn def decrypt_yaml filename = @filename # {{{
93
+ # @brief Decrypts a given file
94
+ #
95
+ # @param [String] filename Valid filename of a file we want to decrypt
96
+ def decrypt_yaml filename = @filename
97
+
98
+ password = ENV[ "PROPERTIES_ENCRYPTION_PASSWORD" ]
99
+ decrypted_yaml = SecureYaml::load( File.open( filename ) )
100
+
101
+ return decrypted_yaml
102
+ end # }}}
103
+
104
+
105
+ attr_reader :contents
106
+
107
+ end
108
+
109
+
110
+ # Direct Invocation
111
+ if __FILE__ == $0
112
+ end # of if __FILE__ == $0
113
+
114
+ # vim:ts=2:tw=100:wm=100
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bjoern Rennhak
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: ruby-try
28
+ name: fpm
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.1
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.1
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ptools
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,272 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: datamapper
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: data_mapper
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: dm-core
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: dm-tags
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: dm-migrations
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: dm-types
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: dm-enum
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: dm-validations
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: dm-timestamps
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: dm-sqlite-adapter
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: dm-do-adapter
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: msgpack
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: faraday
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: mime-types
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :runtime
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: oj
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :runtime
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: moneta
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :runtime
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
293
+ - !ruby/object:Gem::Dependency
294
+ name: pony
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ type: :runtime
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
307
+ - !ruby/object:Gem::Dependency
308
+ name: gettext
309
+ requirement: !ruby/object:Gem::Requirement
310
+ requirements:
311
+ - - ">="
312
+ - !ruby/object:Gem::Version
313
+ version: '0'
314
+ type: :runtime
315
+ prerelease: false
316
+ version_requirements: !ruby/object:Gem::Requirement
317
+ requirements:
318
+ - - ">="
319
+ - !ruby/object:Gem::Version
320
+ version: '0'
321
+ - !ruby/object:Gem::Dependency
322
+ name: rack
323
+ requirement: !ruby/object:Gem::Requirement
324
+ requirements:
325
+ - - ">="
326
+ - !ruby/object:Gem::Version
327
+ version: '0'
328
+ type: :runtime
329
+ prerelease: false
330
+ version_requirements: !ruby/object:Gem::Requirement
331
+ requirements:
332
+ - - ">="
333
+ - !ruby/object:Gem::Version
334
+ version: '0'
69
335
  - !ruby/object:Gem::Dependency
70
336
  name: andand
71
337
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +367,14 @@ files:
101
367
  - bin/fox
102
368
  - fox.gemspec
103
369
  - lib/fox.rb
370
+ - lib/fox/cli.rb
371
+ - lib/fox/configuration.rb
372
+ - lib/fox/core_ext.rb
373
+ - lib/fox/core_ext/array.rb
374
+ - lib/fox/core_ext/hash.rb
375
+ - lib/fox/core_ext/io_binary_read.rb
376
+ - lib/fox/error.rb
377
+ - lib/fox/error/errors.rb
104
378
  - lib/fox/interface/rake/cucumber.rb
105
379
  - lib/fox/interface/rake/default.rb
106
380
  - lib/fox/interface/rake/documentation.rb
@@ -109,15 +383,32 @@ files:
109
383
  - lib/fox/interface/rake/library.rb
110
384
  - lib/fox/interface/rake/metric.rb
111
385
  - lib/fox/interface/rake/rspec.rb
386
+ - lib/fox/interface/thor/all.rb
387
+ - lib/fox/interface/thor/configuration.rb
388
+ - lib/fox/interface/thor/create.rb
389
+ - lib/fox/interface/thor/default.rb
112
390
  - lib/fox/interface/thor/info.thor
391
+ - lib/fox/interface/thor/init.rb
113
392
  - lib/fox/interface/thor/mixin/config_choice.rb
114
393
  - lib/fox/interface/thor/mixin/configuration.rb
394
+ - lib/fox/interface/thor/mixin/database.rb
115
395
  - lib/fox/interface/thor/mixin/default.rb
116
396
  - lib/fox/interface/thor/mixin/default_config.rb
397
+ - lib/fox/interface/thor/mixin/default_model.rb
398
+ - lib/fox/interface/thor/mixin/generators/base_generator.rb
399
+ - lib/fox/interface/thor/mixin/generators/structure.rb
400
+ - lib/fox/interface/thor/mixin/generators/template_loader.rb
117
401
  - lib/fox/interface/thor/mixin/guess.rb
402
+ - lib/fox/interface/thor/mixin/history.rb
118
403
  - lib/fox/interface/thor/mixin/logger.rb
404
+ - lib/fox/interface/thor/mixin/model.rb
119
405
  - lib/fox/interface/thor/mixin/shell.rb
120
- - lib/fox/interface/thor/version.thor
406
+ - lib/fox/interface/thor/new.thor
407
+ - lib/fox/interface/thor/version.rb
408
+ - lib/fox/library/choice.rb
409
+ - lib/fox/library/logger.rb
410
+ - lib/fox/library/project_builder.rb
411
+ - lib/fox/library/secure_config.rb
121
412
  - lib/fox/version.rb
122
413
  - spec/fox_spec.rb
123
414
  - spec/spec_helper.rb