daemon-kit 0.1.8.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/History.txt +10 -3
  2. data/README.rdoc +1 -0
  3. data/daemon-kit.gemspec +6 -2
  4. data/lib/daemon_kit.rb +1 -0
  5. data/lib/daemon_kit/application.rb +3 -3
  6. data/lib/daemon_kit/arguments.rb +18 -8
  7. data/lib/daemon_kit/config.rb +2 -0
  8. data/lib/daemon_kit/dk_sqs.rb +35 -0
  9. data/lib/daemon_kit/generators.rb +1 -3
  10. data/lib/daemon_kit/initializer.rb +10 -3
  11. data/lib/daemon_kit/version.rb +1 -1
  12. data/lib/generators/daemon_kit/amqp/templates/libexec/%app_name%-daemon.rb +3 -5
  13. data/lib/generators/daemon_kit/app/app_generator.rb +3 -1
  14. data/lib/generators/daemon_kit/app/templates/Gemfile +2 -2
  15. data/lib/generators/daemon_kit/app/templates/README.tt +7 -0
  16. data/lib/generators/daemon_kit/app/templates/config/environment.rb.tt +1 -1
  17. data/lib/generators/daemon_kit/rspec/rspec_generator.rb +10 -0
  18. data/lib/generators/daemon_kit/rspec/templates/spec/spec_helper.rb +3 -4
  19. data/lib/generators/daemon_kit/rspec/templates/tasks/rspec.rake +9 -17
  20. data/lib/generators/daemon_kit/sqs/USAGE +5 -0
  21. data/lib/generators/daemon_kit/sqs/sqs_generator.rb +24 -0
  22. data/lib/generators/daemon_kit/sqs/templates/config/pre-daemonize/sqs.rb +6 -0
  23. data/lib/generators/daemon_kit/sqs/templates/config/sqs.yml +20 -0
  24. data/lib/generators/daemon_kit/sqs/templates/libexec/%app_name%-daemon.rb +39 -0
  25. data/spec/daemon_kit_spec.rb +3 -1
  26. data/spec/initializer_spec.rb +4 -0
  27. data/tasks/rspec.rake +5 -17
  28. data/test/test_sqs_generator.rb +48 -0
  29. metadata +148 -181
  30. data/PostInstall.txt +0 -6
  31. data/lib/daemon_kit/vendor/thor-0.13.6/CHANGELOG.rdoc +0 -89
  32. data/lib/daemon_kit/vendor/thor-0.13.6/LICENSE +0 -20
  33. data/lib/daemon_kit/vendor/thor-0.13.6/README.rdoc +0 -297
  34. data/lib/daemon_kit/vendor/thor-0.13.6/Thorfile +0 -69
  35. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor.rb +0 -244
  36. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions.rb +0 -296
  37. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/create_file.rb +0 -103
  38. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/directory.rb +0 -91
  39. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/empty_directory.rb +0 -134
  40. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/file_manipulation.rb +0 -223
  41. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/inject_into_file.rb +0 -104
  42. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/base.rb +0 -540
  43. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/file_binary_read.rb +0 -9
  44. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/hash_with_indifferent_access.rb +0 -75
  45. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/ordered_hash.rb +0 -100
  46. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/error.rb +0 -30
  47. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/group.rb +0 -271
  48. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/invocation.rb +0 -180
  49. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser.rb +0 -4
  50. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/argument.rb +0 -67
  51. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/arguments.rb +0 -150
  52. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/option.rb +0 -128
  53. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/options.rb +0 -169
  54. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/rake_compat.rb +0 -66
  55. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/runner.rb +0 -314
  56. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell.rb +0 -83
  57. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/basic.rb +0 -239
  58. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/color.rb +0 -108
  59. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/task.rb +0 -102
  60. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/util.rb +0 -224
  61. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/version.rb +0 -3
@@ -1,244 +0,0 @@
1
- require 'thor/base'
2
-
3
- # TODO: Update thor to allow for git-style CLI (git bisect run)
4
- class Thor
5
- class << self
6
- # Sets the default task when thor is executed without an explicit task to be called.
7
- #
8
- # ==== Parameters
9
- # meth<Symbol>:: name of the defaut task
10
- #
11
- def default_task(meth=nil)
12
- case meth
13
- when :none
14
- @default_task = 'help'
15
- when nil
16
- @default_task ||= from_superclass(:default_task, 'help')
17
- else
18
- @default_task = meth.to_s
19
- end
20
- end
21
-
22
- # Defines the usage and the description of the next task.
23
- #
24
- # ==== Parameters
25
- # usage<String>
26
- # description<String>
27
- #
28
- def desc(usage, description, options={})
29
- if options[:for]
30
- task = find_and_refresh_task(options[:for])
31
- task.usage = usage if usage
32
- task.description = description if description
33
- else
34
- @usage, @desc = usage, description
35
- end
36
- end
37
-
38
- # Maps an input to a task. If you define:
39
- #
40
- # map "-T" => "list"
41
- #
42
- # Running:
43
- #
44
- # thor -T
45
- #
46
- # Will invoke the list task.
47
- #
48
- # ==== Parameters
49
- # Hash[String|Array => Symbol]:: Maps the string or the strings in the array to the given task.
50
- #
51
- def map(mappings=nil)
52
- @map ||= from_superclass(:map, {})
53
-
54
- if mappings
55
- mappings.each do |key, value|
56
- if key.respond_to?(:each)
57
- key.each {|subkey| @map[subkey] = value}
58
- else
59
- @map[key] = value
60
- end
61
- end
62
- end
63
-
64
- @map
65
- end
66
-
67
- # Declares the options for the next task to be declared.
68
- #
69
- # ==== Parameters
70
- # Hash[Symbol => Object]:: The hash key is the name of the option and the value
71
- # is the type of the option. Can be :string, :array, :hash, :boolean, :numeric
72
- # or :required (string). If you give a value, the type of the value is used.
73
- #
74
- def method_options(options=nil)
75
- @method_options ||= {}
76
- build_options(options, @method_options) if options
77
- @method_options
78
- end
79
-
80
- # Adds an option to the set of method options. If :for is given as option,
81
- # it allows you to change the options from a previous defined task.
82
- #
83
- # def previous_task
84
- # # magic
85
- # end
86
- #
87
- # method_option :foo => :bar, :for => :previous_task
88
- #
89
- # def next_task
90
- # # magic
91
- # end
92
- #
93
- # ==== Parameters
94
- # name<Symbol>:: The name of the argument.
95
- # options<Hash>:: Described below.
96
- #
97
- # ==== Options
98
- # :desc - Description for the argument.
99
- # :required - If the argument is required or not.
100
- # :default - Default value for this argument. It cannot be required and have default values.
101
- # :aliases - Aliases for this option.
102
- # :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean.
103
- # :banner - String to show on usage notes.
104
- #
105
- def method_option(name, options={})
106
- scope = if options[:for]
107
- find_and_refresh_task(options[:for]).options
108
- else
109
- method_options
110
- end
111
-
112
- build_option(name, options, scope)
113
- end
114
-
115
- # Parses the task and options from the given args, instantiate the class
116
- # and invoke the task. This method is used when the arguments must be parsed
117
- # from an array. If you are inside Ruby and want to use a Thor class, you
118
- # can simply initialize it:
119
- #
120
- # script = MyScript.new(args, options, config)
121
- # script.invoke(:task, first_arg, second_arg, third_arg)
122
- #
123
- def start(original_args=ARGV, config={})
124
- super do |given_args|
125
- meth = normalize_task_name(given_args.shift)
126
- task = all_tasks[meth]
127
-
128
- if task
129
- args, opts = Thor::Options.split(given_args)
130
- config.merge!(:task_options => task.options)
131
- else
132
- args, opts = given_args, {}
133
- end
134
-
135
- task ||= Thor::Task::Dynamic.new(meth)
136
- trailing = args[Range.new(arguments.size, -1)]
137
- new(args, opts, config).invoke(task, trailing || [])
138
- end
139
- end
140
-
141
- # Prints help information for the given task.
142
- #
143
- # ==== Parameters
144
- # shell<Thor::Shell>
145
- # task_name<String>
146
- #
147
- def task_help(shell, task_name)
148
- meth = normalize_task_name(task_name)
149
- task = all_tasks[meth]
150
- handle_no_task_error(meth) unless task
151
-
152
- shell.say "Usage:"
153
- shell.say " #{banner(task)}"
154
- shell.say
155
- class_options_help(shell, nil => task.options.map { |_, o| o })
156
- shell.say task.description
157
- end
158
-
159
- # Prints help information for this class.
160
- #
161
- # ==== Parameters
162
- # shell<Thor::Shell>
163
- #
164
- def help(shell)
165
- list = printable_tasks
166
- Thor::Util.thor_classes_in(self).each do |klass|
167
- list += klass.printable_tasks(false)
168
- end
169
- list.sort!{ |a,b| a[0] <=> b[0] }
170
-
171
- shell.say "Tasks:"
172
- shell.print_table(list, :ident => 2, :truncate => true)
173
- shell.say
174
- class_options_help(shell)
175
- end
176
-
177
- # Returns tasks ready to be printed.
178
- def printable_tasks(all=true)
179
- (all ? all_tasks : tasks).map do |_, task|
180
- item = []
181
- item << banner(task)
182
- item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "")
183
- item
184
- end
185
- end
186
-
187
- def handle_argument_error(task, error) #:nodoc:
188
- raise InvocationError, "#{task.name.inspect} was called incorrectly. Call as #{task.formatted_usage(self, banner_base == "thor").inspect}."
189
- end
190
-
191
- protected
192
-
193
- # The banner for this class. You can customize it if you are invoking the
194
- # thor class by another ways which is not the Thor::Runner. It receives
195
- # the task that is going to be invoked and a boolean which indicates if
196
- # the namespace should be displayed as arguments.
197
- #
198
- def banner(task)
199
- "#{banner_base} #{task.formatted_usage(self, banner_base == "thor")}"
200
- end
201
-
202
- def baseclass #:nodoc:
203
- Thor
204
- end
205
-
206
- def create_task(meth) #:nodoc:
207
- if @usage && @desc
208
- tasks[meth.to_s] = Thor::Task.new(meth, @desc, @usage, method_options)
209
- @usage, @desc, @method_options = nil
210
- true
211
- elsif self.all_tasks[meth.to_s] || meth.to_sym == :method_missing
212
- true
213
- else
214
- puts "[WARNING] Attempted to create task #{meth.inspect} without usage or description. " <<
215
- "Call desc if you want this method to be available as task or declare it inside a " <<
216
- "no_tasks{} block. Invoked from #{caller[1].inspect}."
217
- false
218
- end
219
- end
220
-
221
- def initialize_added #:nodoc:
222
- class_options.merge!(method_options)
223
- @method_options = nil
224
- end
225
-
226
- # Receives a task name (can be nil), and try to get a map from it.
227
- # If a map can't be found use the sent name or the default task.
228
- #
229
- def normalize_task_name(meth) #:nodoc:
230
- mapping = map[meth.to_s]
231
- meth = mapping || meth || default_task
232
- meth.to_s.gsub('-','_') # treat foo-bar > foo_bar
233
- end
234
- end
235
-
236
- include Thor::Base
237
-
238
- map HELP_MAPPINGS => :help
239
-
240
- desc "help [TASK]", "Describe available tasks or one specific task"
241
- def help(task=nil)
242
- task ? self.class.task_help(shell, task) : self.class.help(shell)
243
- end
244
- end
@@ -1,296 +0,0 @@
1
- require 'fileutils'
2
- require 'uri'
3
- require 'thor/core_ext/file_binary_read'
4
-
5
- Dir[File.join(File.dirname(__FILE__), "actions", "*.rb")].each do |action|
6
- require action
7
- end
8
-
9
- class Thor
10
- module Actions
11
- attr_accessor :behavior
12
-
13
- def self.included(base) #:nodoc:
14
- base.extend ClassMethods
15
- end
16
-
17
- module ClassMethods
18
- # Hold source paths for one Thor instance. source_paths_for_search is the
19
- # method responsible to gather source_paths from this current class,
20
- # inherited paths and the source root.
21
- #
22
- def source_paths
23
- @_source_paths ||= []
24
- end
25
-
26
- # Stores and return the source root for this class
27
- def source_root(path=nil)
28
- @_source_root = path if path
29
- @_source_root
30
- end
31
-
32
- # Returns the source paths in the following order:
33
- #
34
- # 1) This class source paths
35
- # 2) Source root
36
- # 3) Parents source paths
37
- #
38
- def source_paths_for_search
39
- paths = []
40
- paths += self.source_paths
41
- paths << self.source_root if self.source_root
42
- paths += from_superclass(:source_paths, [])
43
- paths
44
- end
45
-
46
- # Add runtime options that help actions execution.
47
- #
48
- def add_runtime_options!
49
- class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
50
- :desc => "Overwrite files that already exist"
51
-
52
- class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
53
- :desc => "Run but do not make any changes"
54
-
55
- class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
56
- :desc => "Supress status output"
57
-
58
- class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
59
- :desc => "Skip files that already exist"
60
- end
61
- end
62
-
63
- # Extends initializer to add more configuration options.
64
- #
65
- # ==== Configuration
66
- # behavior<Symbol>:: The actions default behavior. Can be :invoke or :revoke.
67
- # It also accepts :force, :skip and :pretend to set the behavior
68
- # and the respective option.
69
- #
70
- # destination_root<String>:: The root directory needed for some actions.
71
- #
72
- def initialize(args=[], options={}, config={})
73
- self.behavior = case config[:behavior].to_s
74
- when "force", "skip"
75
- _cleanup_options_and_set(options, config[:behavior])
76
- :invoke
77
- when "revoke"
78
- :revoke
79
- else
80
- :invoke
81
- end
82
-
83
- super
84
- self.destination_root = config[:destination_root]
85
- end
86
-
87
- # Wraps an action object and call it accordingly to the thor class behavior.
88
- #
89
- def action(instance) #:nodoc:
90
- if behavior == :revoke
91
- instance.revoke!
92
- else
93
- instance.invoke!
94
- end
95
- end
96
-
97
- # Returns the root for this thor class (also aliased as destination root).
98
- #
99
- def destination_root
100
- @destination_stack.last
101
- end
102
-
103
- # Sets the root for this thor class. Relatives path are added to the
104
- # directory where the script was invoked and expanded.
105
- #
106
- def destination_root=(root)
107
- @destination_stack ||= []
108
- @destination_stack[0] = File.expand_path(root || '')
109
- end
110
-
111
- # Returns the given path relative to the absolute root (ie, root where
112
- # the script started).
113
- #
114
- def relative_to_original_destination_root(path, remove_dot=true)
115
- path = path.gsub(@destination_stack[0], '.')
116
- remove_dot ? (path[2..-1] || '') : path
117
- end
118
-
119
- # Holds source paths in instance so they can be manipulated.
120
- #
121
- def source_paths
122
- @source_paths ||= self.class.source_paths_for_search
123
- end
124
-
125
- # Receives a file or directory and search for it in the source paths.
126
- #
127
- def find_in_source_paths(file)
128
- relative_root = relative_to_original_destination_root(destination_root, false)
129
-
130
- source_paths.each do |source|
131
- source_file = File.expand_path(file, File.join(source, relative_root))
132
- return source_file if File.exists?(source_file)
133
- end
134
-
135
- message = "Could not find #{file.inspect} in any of your source paths. "
136
-
137
- unless self.class.source_root
138
- message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
139
- end
140
-
141
- if source_paths.empty?
142
- message << "Currently you have no source paths."
143
- else
144
- message << "Your current source paths are: \n#{source_paths.join("\n")}"
145
- end
146
-
147
- raise Error, message
148
- end
149
-
150
- # Do something in the root or on a provided subfolder. If a relative path
151
- # is given it's referenced from the current root. The full path is yielded
152
- # to the block you provide. The path is set back to the previous path when
153
- # the method exits.
154
- #
155
- # ==== Parameters
156
- # dir<String>:: the directory to move to.
157
- # config<Hash>:: give :verbose => true to log and use padding.
158
- #
159
- def inside(dir='', config={}, &block)
160
- verbose = config.fetch(:verbose, false)
161
-
162
- say_status :inside, dir, verbose
163
- shell.padding += 1 if verbose
164
- @destination_stack.push File.expand_path(dir, destination_root)
165
-
166
- FileUtils.mkdir_p(destination_root) unless File.exist?(destination_root)
167
- FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
168
-
169
- @destination_stack.pop
170
- shell.padding -= 1 if verbose
171
- end
172
-
173
- # Goes to the root and execute the given block.
174
- #
175
- def in_root
176
- inside(@destination_stack.first) { yield }
177
- end
178
-
179
- # Loads an external file and execute it in the instance binding.
180
- #
181
- # ==== Parameters
182
- # path<String>:: The path to the file to execute. Can be a web address or
183
- # a relative path from the source root.
184
- #
185
- # ==== Examples
186
- #
187
- # apply "http://gist.github.com/103208"
188
- #
189
- # apply "recipes/jquery.rb"
190
- #
191
- def apply(path, config={})
192
- verbose = config.fetch(:verbose, true)
193
- path = find_in_source_paths(path) unless path =~ /^http\:\/\//
194
-
195
- say_status :apply, path, verbose
196
- shell.padding += 1 if verbose
197
-
198
- if URI(path).is_a?(URI::HTTP)
199
- contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read }
200
- else
201
- contents = open(path) {|io| io.read }
202
- end
203
-
204
- instance_eval(contents, path)
205
- shell.padding -= 1 if verbose
206
- end
207
-
208
- # Executes a command returning the contents of the command.
209
- #
210
- # ==== Parameters
211
- # command<String>:: the command to be executed.
212
- # config<Hash>:: give :verbose => false to not log the status. Specify :with
213
- # to append an executable to command executation.
214
- #
215
- # ==== Example
216
- #
217
- # inside('vendor') do
218
- # run('ln -s ~/edge rails')
219
- # end
220
- #
221
- def run(command, config={})
222
- return unless behavior == :invoke
223
-
224
- destination = relative_to_original_destination_root(destination_root, false)
225
- desc = "#{command} from #{destination.inspect}"
226
-
227
- if config[:with]
228
- desc = "#{File.basename(config[:with].to_s)} #{desc}"
229
- command = "#{config[:with]} #{command}"
230
- end
231
-
232
- say_status :run, desc, config.fetch(:verbose, true)
233
- `#{command}` unless options[:pretend]
234
- end
235
-
236
- # Executes a ruby script (taking into account WIN32 platform quirks).
237
- #
238
- # ==== Parameters
239
- # command<String>:: the command to be executed.
240
- # config<Hash>:: give :verbose => false to not log the status.
241
- #
242
- def run_ruby_script(command, config={})
243
- return unless behavior == :invoke
244
- run command, config.merge(:with => Thor::Util.ruby_command)
245
- end
246
-
247
- # Run a thor command. A hash of options can be given and it's converted to
248
- # switches.
249
- #
250
- # ==== Parameters
251
- # task<String>:: the task to be invoked
252
- # args<Array>:: arguments to the task
253
- # config<Hash>:: give :verbose => false to not log the status. Other options
254
- # are given as parameter to Thor.
255
- #
256
- # ==== Examples
257
- #
258
- # thor :install, "http://gist.github.com/103208"
259
- # #=> thor install http://gist.github.com/103208
260
- #
261
- # thor :list, :all => true, :substring => 'rails'
262
- # #=> thor list --all --substring=rails
263
- #
264
- def thor(task, *args)
265
- config = args.last.is_a?(Hash) ? args.pop : {}
266
- verbose = config.key?(:verbose) ? config.delete(:verbose) : true
267
- pretend = config.key?(:pretend) ? config.delete(:pretend) : false
268
-
269
- args.unshift task
270
- args.push Thor::Options.to_switches(config)
271
- command = args.join(' ').strip
272
-
273
- run command, :with => :thor, :verbose => verbose, :pretend => pretend
274
- end
275
-
276
- protected
277
-
278
- # Allow current root to be shared between invocations.
279
- #
280
- def _shared_configuration #:nodoc:
281
- super.merge!(:destination_root => self.destination_root)
282
- end
283
-
284
- def _cleanup_options_and_set(options, key) #:nodoc:
285
- case options
286
- when Array
287
- %w(--force -f --skip -s).each { |i| options.delete(i) }
288
- options << "--#{key}"
289
- when Hash
290
- [:force, :skip, "force", "skip"].each { |i| options.delete(i) }
291
- options.merge!(key => true)
292
- end
293
- end
294
-
295
- end
296
- end