angry_mob 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/LICENSE +21 -0
  2. data/README.md +123 -0
  3. data/bin/mob +139 -0
  4. data/lib/angry_mob.rb +28 -0
  5. data/lib/angry_mob/act.rb +111 -0
  6. data/lib/angry_mob/act/scheduler.rb +143 -0
  7. data/lib/angry_mob/action.rb +11 -0
  8. data/lib/angry_mob/builder.rb +115 -0
  9. data/lib/angry_mob/extend.rb +10 -0
  10. data/lib/angry_mob/extend/array.rb +30 -0
  11. data/lib/angry_mob/extend/blank.rb +108 -0
  12. data/lib/angry_mob/extend/blankslate.rb +109 -0
  13. data/lib/angry_mob/extend/dictionary.rb +140 -0
  14. data/lib/angry_mob/extend/hash.rb +67 -0
  15. data/lib/angry_mob/extend/object.rb +21 -0
  16. data/lib/angry_mob/extend/pathname.rb +23 -0
  17. data/lib/angry_mob/extend/string.rb +8 -0
  18. data/lib/angry_mob/log.rb +28 -0
  19. data/lib/angry_mob/mob.rb +77 -0
  20. data/lib/angry_mob/mob_loader.rb +115 -0
  21. data/lib/angry_mob/node.rb +44 -0
  22. data/lib/angry_mob/notifier.rb +76 -0
  23. data/lib/angry_mob/target.rb +257 -0
  24. data/lib/angry_mob/target/arguments.rb +71 -0
  25. data/lib/angry_mob/target/call.rb +57 -0
  26. data/lib/angry_mob/target/default_resource_locator.rb +11 -0
  27. data/lib/angry_mob/target/defaults.rb +23 -0
  28. data/lib/angry_mob/target/mother.rb +66 -0
  29. data/lib/angry_mob/target/notify.rb +57 -0
  30. data/lib/angry_mob/target/tracking.rb +96 -0
  31. data/lib/angry_mob/ui.rb +247 -0
  32. data/lib/angry_mob/util.rb +11 -0
  33. data/lib/angry_mob/vendored.rb +8 -0
  34. data/lib/angry_mob/version.rb +3 -0
  35. data/vendor/angry_hash/Rakefile +17 -0
  36. data/vendor/angry_hash/VERSION +1 -0
  37. data/vendor/angry_hash/angry_hash.gemspec +47 -0
  38. data/vendor/angry_hash/examples/accessors_eg.rb +46 -0
  39. data/vendor/angry_hash/examples/creation_eg.rb +43 -0
  40. data/vendor/angry_hash/examples/dsl.eg.rb +18 -0
  41. data/vendor/angry_hash/examples/dup_eg.rb +86 -0
  42. data/vendor/angry_hash/examples/eg_helper.rb +24 -0
  43. data/vendor/angry_hash/examples/merge_eg.rb +135 -0
  44. data/vendor/angry_hash/lib/angry_hash.rb +215 -0
  45. data/vendor/angry_hash/lib/angry_hash/dsl.rb +44 -0
  46. data/vendor/angry_hash/lib/angry_hash/extension_tracking.rb +12 -0
  47. data/vendor/angry_hash/lib/angry_hash/merge_string.rb +58 -0
  48. data/vendor/json/COPYING +58 -0
  49. data/vendor/json/GPL +340 -0
  50. data/vendor/json/README +360 -0
  51. data/vendor/json/lib/json/common.rb +371 -0
  52. data/vendor/json/lib/json/pure.rb +77 -0
  53. data/vendor/json/lib/json/pure/generator.rb +443 -0
  54. data/vendor/json/lib/json/pure/parser.rb +303 -0
  55. data/vendor/json/lib/json/version.rb +8 -0
  56. data/vendor/thor/CHANGELOG.rdoc +89 -0
  57. data/vendor/thor/LICENSE +20 -0
  58. data/vendor/thor/README.rdoc +297 -0
  59. data/vendor/thor/Thorfile +69 -0
  60. data/vendor/thor/bin/rake2thor +86 -0
  61. data/vendor/thor/bin/thor +6 -0
  62. data/vendor/thor/lib/thor.rb +244 -0
  63. data/vendor/thor/lib/thor/actions.rb +275 -0
  64. data/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  65. data/vendor/thor/lib/thor/actions/directory.rb +91 -0
  66. data/vendor/thor/lib/thor/actions/empty_directory.rb +134 -0
  67. data/vendor/thor/lib/thor/actions/file_manipulation.rb +223 -0
  68. data/vendor/thor/lib/thor/actions/inject_into_file.rb +104 -0
  69. data/vendor/thor/lib/thor/base.rb +540 -0
  70. data/vendor/thor/lib/thor/core_ext/file_binary_read.rb +9 -0
  71. data/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  72. data/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
  73. data/vendor/thor/lib/thor/error.rb +30 -0
  74. data/vendor/thor/lib/thor/group.rb +271 -0
  75. data/vendor/thor/lib/thor/invocation.rb +180 -0
  76. data/vendor/thor/lib/thor/parser.rb +4 -0
  77. data/vendor/thor/lib/thor/parser/argument.rb +67 -0
  78. data/vendor/thor/lib/thor/parser/arguments.rb +150 -0
  79. data/vendor/thor/lib/thor/parser/option.rb +128 -0
  80. data/vendor/thor/lib/thor/parser/options.rb +169 -0
  81. data/vendor/thor/lib/thor/rake_compat.rb +66 -0
  82. data/vendor/thor/lib/thor/runner.rb +314 -0
  83. data/vendor/thor/lib/thor/shell.rb +83 -0
  84. data/vendor/thor/lib/thor/shell/basic.rb +239 -0
  85. data/vendor/thor/lib/thor/shell/color.rb +108 -0
  86. data/vendor/thor/lib/thor/task.rb +102 -0
  87. data/vendor/thor/lib/thor/util.rb +224 -0
  88. data/vendor/thor/lib/thor/version.rb +3 -0
  89. data/vendor/thor/spec/actions/create_file_spec.rb +170 -0
  90. data/vendor/thor/spec/actions/directory_spec.rb +131 -0
  91. data/vendor/thor/spec/actions/empty_directory_spec.rb +91 -0
  92. data/vendor/thor/spec/actions/file_manipulation_spec.rb +271 -0
  93. data/vendor/thor/spec/actions/inject_into_file_spec.rb +135 -0
  94. data/vendor/thor/spec/actions_spec.rb +292 -0
  95. data/vendor/thor/spec/base_spec.rb +263 -0
  96. data/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
  97. data/vendor/thor/spec/core_ext/ordered_hash_spec.rb +115 -0
  98. data/vendor/thor/spec/fixtures/application.rb +2 -0
  99. data/vendor/thor/spec/fixtures/bundle/execute.rb +6 -0
  100. data/vendor/thor/spec/fixtures/bundle/main.thor +1 -0
  101. data/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  102. data/vendor/thor/spec/fixtures/doc/README +3 -0
  103. data/vendor/thor/spec/fixtures/doc/config.rb +1 -0
  104. data/vendor/thor/spec/fixtures/group.thor +90 -0
  105. data/vendor/thor/spec/fixtures/invoke.thor +112 -0
  106. data/vendor/thor/spec/fixtures/script.thor +145 -0
  107. data/vendor/thor/spec/fixtures/task.thor +10 -0
  108. data/vendor/thor/spec/group_spec.rb +171 -0
  109. data/vendor/thor/spec/invocation_spec.rb +107 -0
  110. data/vendor/thor/spec/parser/argument_spec.rb +47 -0
  111. data/vendor/thor/spec/parser/arguments_spec.rb +64 -0
  112. data/vendor/thor/spec/parser/option_spec.rb +202 -0
  113. data/vendor/thor/spec/parser/options_spec.rb +292 -0
  114. data/vendor/thor/spec/rake_compat_spec.rb +68 -0
  115. data/vendor/thor/spec/runner_spec.rb +210 -0
  116. data/vendor/thor/spec/shell/basic_spec.rb +205 -0
  117. data/vendor/thor/spec/shell/color_spec.rb +41 -0
  118. data/vendor/thor/spec/shell_spec.rb +34 -0
  119. data/vendor/thor/spec/spec.opts +1 -0
  120. data/vendor/thor/spec/spec_helper.rb +54 -0
  121. data/vendor/thor/spec/task_spec.rb +69 -0
  122. data/vendor/thor/spec/thor_spec.rb +237 -0
  123. data/vendor/thor/spec/util_spec.rb +163 -0
  124. data/vendor/thor/thor.gemspec +120 -0
  125. metadata +199 -0
@@ -0,0 +1,9 @@
1
+ class File #:nodoc:
2
+
3
+ unless File.respond_to?(:binread)
4
+ def self.binread(file)
5
+ File.open(file, 'rb') { |f| f.read }
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,75 @@
1
+ class Thor
2
+ module CoreExt #:nodoc:
3
+
4
+ # A hash with indifferent access and magic predicates.
5
+ #
6
+ # hash = Thor::CoreExt::HashWithIndifferentAccess.new 'foo' => 'bar', 'baz' => 'bee', 'force' => true
7
+ #
8
+ # hash[:foo] #=> 'bar'
9
+ # hash['foo'] #=> 'bar'
10
+ # hash.foo? #=> true
11
+ #
12
+ class HashWithIndifferentAccess < ::Hash #:nodoc:
13
+
14
+ def initialize(hash={})
15
+ super()
16
+ hash.each do |key, value|
17
+ self[convert_key(key)] = value
18
+ end
19
+ end
20
+
21
+ def [](key)
22
+ super(convert_key(key))
23
+ end
24
+
25
+ def []=(key, value)
26
+ super(convert_key(key), value)
27
+ end
28
+
29
+ def delete(key)
30
+ super(convert_key(key))
31
+ end
32
+
33
+ def values_at(*indices)
34
+ indices.collect { |key| self[convert_key(key)] }
35
+ end
36
+
37
+ def merge(other)
38
+ dup.merge!(other)
39
+ end
40
+
41
+ def merge!(other)
42
+ other.each do |key, value|
43
+ self[convert_key(key)] = value
44
+ end
45
+ self
46
+ end
47
+
48
+ protected
49
+
50
+ def convert_key(key)
51
+ key.is_a?(Symbol) ? key.to_s : key
52
+ end
53
+
54
+ # Magic predicates. For instance:
55
+ #
56
+ # options.force? # => !!options['force']
57
+ # options.shebang # => "/usr/lib/local/ruby"
58
+ # options.test_framework?(:rspec) # => options[:test_framework] == :rspec
59
+ #
60
+ def method_missing(method, *args, &block)
61
+ method = method.to_s
62
+ if method =~ /^(\w+)\?$/
63
+ if args.empty?
64
+ !!self[$1]
65
+ else
66
+ self[$1] == args.first
67
+ end
68
+ else
69
+ self[method]
70
+ end
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,100 @@
1
+ class Thor
2
+ module CoreExt #:nodoc:
3
+
4
+ if RUBY_VERSION >= '1.9'
5
+ class OrderedHash < ::Hash
6
+ end
7
+ else
8
+ # This class is based on the Ruby 1.9 ordered hashes.
9
+ #
10
+ # It keeps the semantics and most of the efficiency of normal hashes
11
+ # while also keeping track of the order in which elements were set.
12
+ #
13
+ class OrderedHash #:nodoc:
14
+ include Enumerable
15
+
16
+ Node = Struct.new(:key, :value, :next, :prev)
17
+
18
+ def initialize
19
+ @hash = {}
20
+ end
21
+
22
+ def [](key)
23
+ @hash[key] && @hash[key].value
24
+ end
25
+
26
+ def []=(key, value)
27
+ if node = @hash[key]
28
+ node.value = value
29
+ else
30
+ node = Node.new(key, value)
31
+
32
+ if @first.nil?
33
+ @first = @last = node
34
+ else
35
+ node.prev = @last
36
+ @last.next = node
37
+ @last = node
38
+ end
39
+ end
40
+
41
+ @hash[key] = node
42
+ value
43
+ end
44
+
45
+ def delete(key)
46
+ if node = @hash[key]
47
+ prev_node = node.prev
48
+ next_node = node.next
49
+
50
+ next_node.prev = prev_node if next_node
51
+ prev_node.next = next_node if prev_node
52
+
53
+ @first = next_node if @first == node
54
+ @last = prev_node if @last == node
55
+
56
+ value = node.value
57
+ end
58
+
59
+ @hash.delete(key)
60
+ value
61
+ end
62
+
63
+ def keys
64
+ self.map { |k, v| k }
65
+ end
66
+
67
+ def values
68
+ self.map { |k, v| v }
69
+ end
70
+
71
+ def each
72
+ return unless @first
73
+ yield [@first.key, @first.value]
74
+ node = @first
75
+ yield [node.key, node.value] while node = node.next
76
+ self
77
+ end
78
+
79
+ def merge(other)
80
+ hash = self.class.new
81
+
82
+ self.each do |key, value|
83
+ hash[key] = value
84
+ end
85
+
86
+ other.each do |key, value|
87
+ hash[key] = value
88
+ end
89
+
90
+ hash
91
+ end
92
+
93
+ def empty?
94
+ @hash.empty?
95
+ end
96
+ end
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,30 @@
1
+ class Thor
2
+ # Thor::Error is raised when it's caused by wrong usage of thor classes. Those
3
+ # errors have their backtrace supressed and are nicely shown to the user.
4
+ #
5
+ # Errors that are caused by the developer, like declaring a method which
6
+ # overwrites a thor keyword, it SHOULD NOT raise a Thor::Error. This way, we
7
+ # ensure that developer errors are shown with full backtrace.
8
+ #
9
+ class Error < StandardError
10
+ end
11
+
12
+ # Raised when a task was not found.
13
+ #
14
+ class UndefinedTaskError < Error
15
+ end
16
+
17
+ # Raised when a task was found, but not invoked properly.
18
+ #
19
+ class InvocationError < Error
20
+ end
21
+
22
+ class UnknownArgumentError < Error
23
+ end
24
+
25
+ class RequiredArgumentMissingError < InvocationError
26
+ end
27
+
28
+ class MalformattedArgumentError < InvocationError
29
+ end
30
+ end
@@ -0,0 +1,271 @@
1
+ require 'thor/base'
2
+
3
+ # Thor has a special class called Thor::Group. The main difference to Thor class
4
+ # is that it invokes all tasks at once. It also include some methods that allows
5
+ # invocations to be done at the class method, which are not available to Thor
6
+ # tasks.
7
+ class Thor::Group
8
+ class << self
9
+ # The descrition for this Thor::Group. If none is provided, but a source root
10
+ # exists, tries to find the USAGE one folder above it, otherwise searches
11
+ # in the superclass.
12
+ #
13
+ # ==== Parameters
14
+ # description<String>:: The description for this Thor::Group.
15
+ #
16
+ def desc(description=nil)
17
+ case description
18
+ when nil
19
+ @desc ||= from_superclass(:desc, nil)
20
+ else
21
+ @desc = description
22
+ end
23
+ end
24
+
25
+ # Start works differently in Thor::Group, it simply invokes all tasks
26
+ # inside the class.
27
+ #
28
+ def start(original_args=ARGV, config={})
29
+ super do |given_args|
30
+ if Thor::HELP_MAPPINGS.include?(given_args.first)
31
+ help(config[:shell])
32
+ return
33
+ end
34
+
35
+ args, opts = Thor::Options.split(given_args)
36
+ new(args, opts, config).invoke
37
+ end
38
+ end
39
+
40
+ # Prints help information.
41
+ #
42
+ # ==== Options
43
+ # short:: When true, shows only usage.
44
+ #
45
+ def help(shell)
46
+ shell.say "Usage:"
47
+ shell.say " #{banner}\n"
48
+ shell.say
49
+ class_options_help(shell)
50
+ shell.say self.desc if self.desc
51
+ end
52
+
53
+ # Stores invocations for this class merging with superclass values.
54
+ #
55
+ def invocations #:nodoc:
56
+ @invocations ||= from_superclass(:invocations, {})
57
+ end
58
+
59
+ # Stores invocation blocks used on invoke_from_option.
60
+ #
61
+ def invocation_blocks #:nodoc:
62
+ @invocation_blocks ||= from_superclass(:invocation_blocks, {})
63
+ end
64
+
65
+ # Invoke the given namespace or class given. It adds an instance
66
+ # method that will invoke the klass and task. You can give a block to
67
+ # configure how it will be invoked.
68
+ #
69
+ # The namespace/class given will have its options showed on the help
70
+ # usage. Check invoke_from_option for more information.
71
+ #
72
+ def invoke(*names, &block)
73
+ options = names.last.is_a?(Hash) ? names.pop : {}
74
+ verbose = options.fetch(:verbose, true)
75
+
76
+ names.each do |name|
77
+ invocations[name] = false
78
+ invocation_blocks[name] = block if block_given?
79
+
80
+ class_eval <<-METHOD, __FILE__, __LINE__
81
+ def _invoke_#{name.to_s.gsub(/\W/, '_')}
82
+ klass, task = self.class.prepare_for_invocation(nil, #{name.inspect})
83
+
84
+ if klass
85
+ say_status :invoke, #{name.inspect}, #{verbose.inspect}
86
+ block = self.class.invocation_blocks[#{name.inspect}]
87
+ _invoke_for_class_method klass, task, &block
88
+ else
89
+ say_status :error, %(#{name.inspect} [not found]), :red
90
+ end
91
+ end
92
+ METHOD
93
+ end
94
+ end
95
+
96
+ # Invoke a thor class based on the value supplied by the user to the
97
+ # given option named "name". A class option must be created before this
98
+ # method is invoked for each name given.
99
+ #
100
+ # ==== Examples
101
+ #
102
+ # class GemGenerator < Thor::Group
103
+ # class_option :test_framework, :type => :string
104
+ # invoke_from_option :test_framework
105
+ # end
106
+ #
107
+ # ==== Boolean options
108
+ #
109
+ # In some cases, you want to invoke a thor class if some option is true or
110
+ # false. This is automatically handled by invoke_from_option. Then the
111
+ # option name is used to invoke the generator.
112
+ #
113
+ # ==== Preparing for invocation
114
+ #
115
+ # In some cases you want to customize how a specified hook is going to be
116
+ # invoked. You can do that by overwriting the class method
117
+ # prepare_for_invocation. The class method must necessarily return a klass
118
+ # and an optional task.
119
+ #
120
+ # ==== Custom invocations
121
+ #
122
+ # You can also supply a block to customize how the option is giong to be
123
+ # invoked. The block receives two parameters, an instance of the current
124
+ # class and the klass to be invoked.
125
+ #
126
+ def invoke_from_option(*names, &block)
127
+ options = names.last.is_a?(Hash) ? names.pop : {}
128
+ verbose = options.fetch(:verbose, :white)
129
+
130
+ names.each do |name|
131
+ unless class_options.key?(name)
132
+ raise ArgumentError, "You have to define the option #{name.inspect} " <<
133
+ "before setting invoke_from_option."
134
+ end
135
+
136
+ invocations[name] = true
137
+ invocation_blocks[name] = block if block_given?
138
+
139
+ class_eval <<-METHOD, __FILE__, __LINE__
140
+ def _invoke_from_option_#{name.to_s.gsub(/\W/, '_')}
141
+ return unless options[#{name.inspect}]
142
+
143
+ value = options[#{name.inspect}]
144
+ value = #{name.inspect} if TrueClass === value
145
+ klass, task = self.class.prepare_for_invocation(#{name.inspect}, value)
146
+
147
+ if klass
148
+ say_status :invoke, value, #{verbose.inspect}
149
+ block = self.class.invocation_blocks[#{name.inspect}]
150
+ _invoke_for_class_method klass, task, &block
151
+ else
152
+ say_status :error, %(\#{value} [not found]), :red
153
+ end
154
+ end
155
+ METHOD
156
+ end
157
+ end
158
+
159
+ # Remove a previously added invocation.
160
+ #
161
+ # ==== Examples
162
+ #
163
+ # remove_invocation :test_framework
164
+ #
165
+ def remove_invocation(*names)
166
+ names.each do |name|
167
+ remove_task(name)
168
+ remove_class_option(name)
169
+ invocations.delete(name)
170
+ invocation_blocks.delete(name)
171
+ end
172
+ end
173
+
174
+ # Overwrite class options help to allow invoked generators options to be
175
+ # shown recursively when invoking a generator.
176
+ #
177
+ def class_options_help(shell, groups={}) #:nodoc:
178
+ get_options_from_invocations(groups, class_options) do |klass|
179
+ klass.send(:get_options_from_invocations, groups, class_options)
180
+ end
181
+ super(shell, groups)
182
+ end
183
+
184
+ # Get invocations array and merge options from invocations. Those
185
+ # options are added to group_options hash. Options that already exists
186
+ # in base_options are not added twice.
187
+ #
188
+ def get_options_from_invocations(group_options, base_options) #:nodoc:
189
+ invocations.each do |name, from_option|
190
+ value = if from_option
191
+ option = class_options[name]
192
+ option.type == :boolean ? name : option.default
193
+ else
194
+ name
195
+ end
196
+ next unless value
197
+
198
+ klass, task = prepare_for_invocation(name, value)
199
+ next unless klass && klass.respond_to?(:class_options)
200
+
201
+ value = value.to_s
202
+ human_name = value.respond_to?(:classify) ? value.classify : value
203
+
204
+ group_options[human_name] ||= []
205
+ group_options[human_name] += klass.class_options.values.select do |option|
206
+ base_options[option.name.to_sym].nil? && option.group.nil? &&
207
+ !group_options.values.flatten.any? { |i| i.name == option.name }
208
+ end
209
+
210
+ yield klass if block_given?
211
+ end
212
+ end
213
+
214
+ # Returns tasks ready to be printed.
215
+ def printable_tasks(*)
216
+ item = []
217
+ item << banner
218
+ item << (desc ? "# #{desc.gsub(/\s+/m,' ')}" : "")
219
+ [item]
220
+ end
221
+
222
+ def handle_argument_error(task, error) #:nodoc:
223
+ raise error, "#{task.name.inspect} was called incorrectly. Are you sure it has arity equals to 0?"
224
+ end
225
+
226
+ protected
227
+
228
+ # The banner for this class. You can customize it if you are invoking the
229
+ # thor class by another ways which is not the Thor::Runner.
230
+ def banner
231
+ "#{banner_base} #{self_task.formatted_usage(self, false)}"
232
+ end
233
+
234
+ # Represents the whole class as a task.
235
+ def self_task #:nodoc:
236
+ Thor::Task::Dynamic.new(self.namespace, class_options)
237
+ end
238
+
239
+ def baseclass #:nodoc:
240
+ Thor::Group
241
+ end
242
+
243
+ def create_task(meth) #:nodoc:
244
+ tasks[meth.to_s] = Thor::Task.new(meth, nil, nil, nil)
245
+ true
246
+ end
247
+ end
248
+
249
+ include Thor::Base
250
+
251
+ protected
252
+
253
+ # Shortcut to invoke with padding and block handling. Use internally by
254
+ # invoke and invoke_from_option class methods.
255
+ def _invoke_for_class_method(klass, task=nil, *args, &block) #:nodoc:
256
+ with_padding do
257
+ if block
258
+ case block.arity
259
+ when 3
260
+ block.call(self, klass, task)
261
+ when 2
262
+ block.call(self, klass)
263
+ when 1
264
+ instance_exec(klass, &block)
265
+ end
266
+ else
267
+ invoke klass, task, *args
268
+ end
269
+ end
270
+ end
271
+ end