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.
- data/History.txt +10 -3
- data/README.rdoc +1 -0
- data/daemon-kit.gemspec +6 -2
- data/lib/daemon_kit.rb +1 -0
- data/lib/daemon_kit/application.rb +3 -3
- data/lib/daemon_kit/arguments.rb +18 -8
- data/lib/daemon_kit/config.rb +2 -0
- data/lib/daemon_kit/dk_sqs.rb +35 -0
- data/lib/daemon_kit/generators.rb +1 -3
- data/lib/daemon_kit/initializer.rb +10 -3
- data/lib/daemon_kit/version.rb +1 -1
- data/lib/generators/daemon_kit/amqp/templates/libexec/%app_name%-daemon.rb +3 -5
- data/lib/generators/daemon_kit/app/app_generator.rb +3 -1
- data/lib/generators/daemon_kit/app/templates/Gemfile +2 -2
- data/lib/generators/daemon_kit/app/templates/README.tt +7 -0
- data/lib/generators/daemon_kit/app/templates/config/environment.rb.tt +1 -1
- data/lib/generators/daemon_kit/rspec/rspec_generator.rb +10 -0
- data/lib/generators/daemon_kit/rspec/templates/spec/spec_helper.rb +3 -4
- data/lib/generators/daemon_kit/rspec/templates/tasks/rspec.rake +9 -17
- data/lib/generators/daemon_kit/sqs/USAGE +5 -0
- data/lib/generators/daemon_kit/sqs/sqs_generator.rb +24 -0
- data/lib/generators/daemon_kit/sqs/templates/config/pre-daemonize/sqs.rb +6 -0
- data/lib/generators/daemon_kit/sqs/templates/config/sqs.yml +20 -0
- data/lib/generators/daemon_kit/sqs/templates/libexec/%app_name%-daemon.rb +39 -0
- data/spec/daemon_kit_spec.rb +3 -1
- data/spec/initializer_spec.rb +4 -0
- data/tasks/rspec.rake +5 -17
- data/test/test_sqs_generator.rb +48 -0
- metadata +148 -181
- data/PostInstall.txt +0 -6
- data/lib/daemon_kit/vendor/thor-0.13.6/CHANGELOG.rdoc +0 -89
- data/lib/daemon_kit/vendor/thor-0.13.6/LICENSE +0 -20
- data/lib/daemon_kit/vendor/thor-0.13.6/README.rdoc +0 -297
- data/lib/daemon_kit/vendor/thor-0.13.6/Thorfile +0 -69
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor.rb +0 -244
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions.rb +0 -296
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/create_file.rb +0 -103
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/directory.rb +0 -91
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/empty_directory.rb +0 -134
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/file_manipulation.rb +0 -223
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/inject_into_file.rb +0 -104
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/base.rb +0 -540
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/file_binary_read.rb +0 -9
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/hash_with_indifferent_access.rb +0 -75
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/ordered_hash.rb +0 -100
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/error.rb +0 -30
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/group.rb +0 -271
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/invocation.rb +0 -180
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser.rb +0 -4
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/argument.rb +0 -67
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/arguments.rb +0 -150
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/option.rb +0 -128
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/options.rb +0 -169
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/rake_compat.rb +0 -66
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/runner.rb +0 -314
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell.rb +0 -83
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/basic.rb +0 -239
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/color.rb +0 -108
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/task.rb +0 -102
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/util.rb +0 -224
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/version.rb +0 -3
@@ -1,224 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
|
3
|
-
class Thor
|
4
|
-
module Sandbox #:nodoc:
|
5
|
-
end
|
6
|
-
|
7
|
-
# This module holds several utilities:
|
8
|
-
#
|
9
|
-
# 1) Methods to convert thor namespaces to constants and vice-versa.
|
10
|
-
#
|
11
|
-
# Thor::Utils.namespace_from_thor_class(Foo::Bar::Baz) #=> "foo:bar:baz"
|
12
|
-
#
|
13
|
-
# 2) Loading thor files and sandboxing:
|
14
|
-
#
|
15
|
-
# Thor::Utils.load_thorfile("~/.thor/foo")
|
16
|
-
#
|
17
|
-
module Util
|
18
|
-
|
19
|
-
# Receives a namespace and search for it in the Thor::Base subclasses.
|
20
|
-
#
|
21
|
-
# ==== Parameters
|
22
|
-
# namespace<String>:: The namespace to search for.
|
23
|
-
#
|
24
|
-
def self.find_by_namespace(namespace)
|
25
|
-
namespace = "default#{namespace}" if namespace.empty? || namespace =~ /^:/
|
26
|
-
Thor::Base.subclasses.find { |klass| klass.namespace == namespace }
|
27
|
-
end
|
28
|
-
|
29
|
-
# Receives a constant and converts it to a Thor namespace. Since Thor tasks
|
30
|
-
# can be added to a sandbox, this method is also responsable for removing
|
31
|
-
# the sandbox namespace.
|
32
|
-
#
|
33
|
-
# This method should not be used in general because it's used to deal with
|
34
|
-
# older versions of Thor. On current versions, if you need to get the
|
35
|
-
# namespace from a class, just call namespace on it.
|
36
|
-
#
|
37
|
-
# ==== Parameters
|
38
|
-
# constant<Object>:: The constant to be converted to the thor path.
|
39
|
-
#
|
40
|
-
# ==== Returns
|
41
|
-
# String:: If we receive Foo::Bar::Baz it returns "foo:bar:baz"
|
42
|
-
#
|
43
|
-
def self.namespace_from_thor_class(constant)
|
44
|
-
constant = constant.to_s.gsub(/^Thor::Sandbox::/, "")
|
45
|
-
constant = snake_case(constant).squeeze(":")
|
46
|
-
constant
|
47
|
-
end
|
48
|
-
|
49
|
-
# Given the contents, evaluate it inside the sandbox and returns the
|
50
|
-
# namespaces defined in the sandbox.
|
51
|
-
#
|
52
|
-
# ==== Parameters
|
53
|
-
# contents<String>
|
54
|
-
#
|
55
|
-
# ==== Returns
|
56
|
-
# Array[Object]
|
57
|
-
#
|
58
|
-
def self.namespaces_in_content(contents, file=__FILE__)
|
59
|
-
old_constants = Thor::Base.subclasses.dup
|
60
|
-
Thor::Base.subclasses.clear
|
61
|
-
|
62
|
-
load_thorfile(file, contents)
|
63
|
-
|
64
|
-
new_constants = Thor::Base.subclasses.dup
|
65
|
-
Thor::Base.subclasses.replace(old_constants)
|
66
|
-
|
67
|
-
new_constants.map!{ |c| c.namespace }
|
68
|
-
new_constants.compact!
|
69
|
-
new_constants
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns the thor classes declared inside the given class.
|
73
|
-
#
|
74
|
-
def self.thor_classes_in(klass)
|
75
|
-
stringfied_constants = klass.constants.map { |c| c.to_s }
|
76
|
-
Thor::Base.subclasses.select do |subclass|
|
77
|
-
next unless subclass.name
|
78
|
-
stringfied_constants.include?(subclass.name.gsub("#{klass.name}::", ''))
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# Receives a string and convert it to snake case. SnakeCase returns snake_case.
|
83
|
-
#
|
84
|
-
# ==== Parameters
|
85
|
-
# String
|
86
|
-
#
|
87
|
-
# ==== Returns
|
88
|
-
# String
|
89
|
-
#
|
90
|
-
def self.snake_case(str)
|
91
|
-
return str.downcase if str =~ /^[A-Z_]+$/
|
92
|
-
str.gsub(/\B[A-Z]/, '_\&').squeeze('_') =~ /_*(.*)/
|
93
|
-
return $+.downcase
|
94
|
-
end
|
95
|
-
|
96
|
-
# Receives a string and convert it to camel case. camel_case returns CamelCase.
|
97
|
-
#
|
98
|
-
# ==== Parameters
|
99
|
-
# String
|
100
|
-
#
|
101
|
-
# ==== Returns
|
102
|
-
# String
|
103
|
-
#
|
104
|
-
def self.camel_case(str)
|
105
|
-
return str if str !~ /_/ && str =~ /[A-Z]+.*/
|
106
|
-
str.split('_').map { |i| i.capitalize }.join
|
107
|
-
end
|
108
|
-
|
109
|
-
# Receives a namespace and tries to retrieve a Thor or Thor::Group class
|
110
|
-
# from it. It first searches for a class using the all the given namespace,
|
111
|
-
# if it's not found, removes the highest entry and searches for the class
|
112
|
-
# again. If found, returns the highest entry as the class name.
|
113
|
-
#
|
114
|
-
# ==== Examples
|
115
|
-
#
|
116
|
-
# class Foo::Bar < Thor
|
117
|
-
# def baz
|
118
|
-
# end
|
119
|
-
# end
|
120
|
-
#
|
121
|
-
# class Baz::Foo < Thor::Group
|
122
|
-
# end
|
123
|
-
#
|
124
|
-
# Thor::Util.namespace_to_thor_class("foo:bar") #=> Foo::Bar, nil # will invoke default task
|
125
|
-
# Thor::Util.namespace_to_thor_class("baz:foo") #=> Baz::Foo, nil
|
126
|
-
# Thor::Util.namespace_to_thor_class("foo:bar:baz") #=> Foo::Bar, "baz"
|
127
|
-
#
|
128
|
-
# ==== Parameters
|
129
|
-
# namespace<String>
|
130
|
-
#
|
131
|
-
def self.find_class_and_task_by_namespace(namespace, fallback = true)
|
132
|
-
if namespace.include?(?:) # look for a namespaced task
|
133
|
-
pieces = namespace.split(":")
|
134
|
-
task = pieces.pop
|
135
|
-
klass = Thor::Util.find_by_namespace(pieces.join(":"))
|
136
|
-
end
|
137
|
-
unless klass # look for a Thor::Group with the right name
|
138
|
-
klass, task = Thor::Util.find_by_namespace(namespace), nil
|
139
|
-
end
|
140
|
-
if !klass && fallback # try a task in the default namespace
|
141
|
-
task = namespace
|
142
|
-
klass = Thor::Util.find_by_namespace('')
|
143
|
-
end
|
144
|
-
return klass, task
|
145
|
-
end
|
146
|
-
|
147
|
-
# Receives a path and load the thor file in the path. The file is evaluated
|
148
|
-
# inside the sandbox to avoid namespacing conflicts.
|
149
|
-
#
|
150
|
-
def self.load_thorfile(path, content=nil)
|
151
|
-
content ||= File.binread(path)
|
152
|
-
|
153
|
-
begin
|
154
|
-
Thor::Sandbox.class_eval(content, path)
|
155
|
-
rescue Exception => e
|
156
|
-
$stderr.puts "WARNING: unable to load thorfile #{path.inspect}: #{e.message}"
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def self.user_home
|
161
|
-
@@user_home ||= if ENV["HOME"]
|
162
|
-
ENV["HOME"]
|
163
|
-
elsif ENV["USERPROFILE"]
|
164
|
-
ENV["USERPROFILE"]
|
165
|
-
elsif ENV["HOMEDRIVE"] && ENV["HOMEPATH"]
|
166
|
-
File.join(ENV["HOMEDRIVE"], ENV["HOMEPATH"])
|
167
|
-
elsif ENV["APPDATA"]
|
168
|
-
ENV["APPDATA"]
|
169
|
-
else
|
170
|
-
begin
|
171
|
-
File.expand_path("~")
|
172
|
-
rescue
|
173
|
-
if File::ALT_SEPARATOR
|
174
|
-
"C:/"
|
175
|
-
else
|
176
|
-
"/"
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
# Returns the root where thor files are located, dependending on the OS.
|
183
|
-
#
|
184
|
-
def self.thor_root
|
185
|
-
File.join(user_home, ".thor").gsub(/\\/, '/')
|
186
|
-
end
|
187
|
-
|
188
|
-
# Returns the files in the thor root. On Windows thor_root will be something
|
189
|
-
# like this:
|
190
|
-
#
|
191
|
-
# C:\Documents and Settings\james\.thor
|
192
|
-
#
|
193
|
-
# If we don't #gsub the \ character, Dir.glob will fail.
|
194
|
-
#
|
195
|
-
def self.thor_root_glob
|
196
|
-
files = Dir["#{thor_root}/*"]
|
197
|
-
|
198
|
-
files.map! do |file|
|
199
|
-
File.directory?(file) ? File.join(file, "main.thor") : file
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
# Where to look for Thor files.
|
204
|
-
#
|
205
|
-
def self.globs_for(path)
|
206
|
-
["#{path}/Thorfile", "#{path}/*.thor", "#{path}/tasks/*.thor", "#{path}/lib/tasks/*.thor"]
|
207
|
-
end
|
208
|
-
|
209
|
-
# Return the path to the ruby interpreter taking into account multiple
|
210
|
-
# installations and windows extensions.
|
211
|
-
#
|
212
|
-
def self.ruby_command
|
213
|
-
@ruby_command ||= begin
|
214
|
-
ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
215
|
-
ruby << Config::CONFIG['EXEEXT']
|
216
|
-
|
217
|
-
# escape string in case path to ruby executable contain spaces.
|
218
|
-
ruby.sub!(/.*\s.*/m, '"\&"')
|
219
|
-
ruby
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
end
|
224
|
-
end
|