angry_mob 0.1.0

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.
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,11 @@
1
+ class AngryMob
2
+ class Action
3
+ def initialize(name,default=false)
4
+ @default = default
5
+ end
6
+
7
+ def default?
8
+ !!@default
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,115 @@
1
+ require 'pathname'
2
+ require 'tsort'
3
+
4
+ class AngryMob
5
+ class Builder
6
+ include Log
7
+
8
+ def self.from_file(path)
9
+ path = Pathname(path)
10
+ new.from_file(path)
11
+ end
12
+
13
+ attr_reader :node_consolidation_block
14
+
15
+ def file
16
+ if @file
17
+ @file
18
+ else
19
+ '<no-file>'
20
+ end
21
+ end
22
+
23
+ # read and evaluate a file in builder context
24
+ def from_file(path)
25
+ @file = path
26
+ instance_eval path.read, path.to_s
27
+ @file = nil
28
+ self
29
+ end
30
+
31
+ def to_mob
32
+ mob = Mob.new
33
+
34
+ # pre-setup
35
+ mob.setup_node = lambda {|node,defaults|
36
+ node_setup_blocks.each {|blk| blk[node,defaults]}
37
+ }
38
+
39
+ # in-setup
40
+ mob.node_defaults = lambda {|node,defaults|
41
+ node_default_blocks.each {|blk| blk[node,defaults]}
42
+ }
43
+
44
+ # post-setup
45
+ mob.consolidate_node = @node_consolidation_block
46
+
47
+ # create and bind acts
48
+ acts.each do |name,(blk,file,multi)|
49
+ act = Act.new(name,multi,&blk)
50
+ act.extend helper_mod
51
+ act.bind(mob,file)
52
+ end
53
+
54
+ mob
55
+ end
56
+
57
+ #### DSL API
58
+
59
+ # Defines an `act` block
60
+ def act(name, definition_file=nil, &blk)
61
+ definition_file ||= file
62
+ acts[name.to_sym] = [blk,definition_file.dup,false]
63
+ end
64
+
65
+ def multi_act(name, definition_file=nil, &blk)
66
+ definition_file ||= file
67
+ acts[name.to_sym] = [blk,definition_file.dup,true]
68
+ end
69
+
70
+ def act_helper(&blk)
71
+ helper_mod.module_eval(&blk)
72
+ end
73
+
74
+ def finalise(*act_names, &blk)
75
+ act_names.norm.each {|a| act("finalise/#{a}",&blk)}
76
+ end
77
+
78
+ def notifications_for(name,&blk)
79
+ act("notifications_for/#{name}") { notifications.for(name, :context => self, &blk) }
80
+ end
81
+
82
+ # A `setup_node` block allows the mob to set defaults, load resource locators and anything else you like.
83
+ def setup_node(&blk)
84
+ node_setup_blocks << blk
85
+ end
86
+
87
+ def consolidate_node(&blk)
88
+ @node_consolidation_block = blk
89
+ end
90
+
91
+ # Defaults
92
+ def node_defaults(&blk)
93
+ node_default_blocks << blk
94
+ end
95
+
96
+
97
+ protected
98
+ def node_setup_blocks
99
+ @node_setup_blocks ||= []
100
+ end
101
+
102
+ def node_default_blocks
103
+ @node_default_blocks ||= []
104
+ end
105
+
106
+ def acts
107
+ @acts ||= Dictionary.new
108
+ end
109
+
110
+ def helper_mod
111
+ @helper_mod ||= Module.new
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,10 @@
1
+ %w[
2
+ blank
3
+ dictionary
4
+ object
5
+ array
6
+ string
7
+ pathname
8
+ hash
9
+ blankslate
10
+ ].each {|lib| require "angry_mob/extend/#{lib}" }
@@ -0,0 +1,30 @@
1
+ class Array
2
+ def extract_options!
3
+ if Hash === last then pop else {} end
4
+ end
5
+ def extract_options
6
+ if Hash === last then last else {} end
7
+ end
8
+
9
+ def options
10
+ if Hash === last
11
+ self[-1] = AngryHash.__convert(last)
12
+ else
13
+ opts = AngryHash.new
14
+ push opts
15
+ opts
16
+ end
17
+ end
18
+
19
+ def norm
20
+ n = flatten
21
+ n.compact!
22
+ n
23
+ end
24
+
25
+ def norm!
26
+ flatten!
27
+ compact!
28
+ self
29
+ end
30
+ end
@@ -0,0 +1,108 @@
1
+ # from extlib
2
+ class Object
3
+ ##
4
+ # Returns true if the object is nil or empty (if applicable)
5
+ #
6
+ # [].blank? #=> true
7
+ # [1].blank? #=> false
8
+ # [nil].blank? #=> false
9
+ #
10
+ # @return [TrueClass, FalseClass]
11
+ #
12
+ # @api public
13
+ def blank?
14
+ nil? || (respond_to?(:empty?) && empty?)
15
+ end
16
+ def present?
17
+ ! blank?
18
+ end
19
+ end # class Object
20
+
21
+ class Numeric
22
+ ##
23
+ # Numerics are never blank
24
+ #
25
+ # 0.blank? #=> false
26
+ # 1.blank? #=> false
27
+ # 6.54321.blank? #=> false
28
+ #
29
+ # @return [FalseClass]
30
+ #
31
+ # @api public
32
+ def blank?
33
+ false
34
+ end
35
+ def present?
36
+ true
37
+ end
38
+ end # class Numeric
39
+
40
+ class NilClass
41
+ ##
42
+ # Nil is always blank
43
+ #
44
+ # nil.blank? #=> true
45
+ #
46
+ # @return [TrueClass]
47
+ #
48
+ # @api public
49
+ def blank?
50
+ true
51
+ end
52
+ def present?
53
+ false
54
+ end
55
+ end # class NilClass
56
+
57
+ class TrueClass
58
+ ##
59
+ # True is never blank.
60
+ #
61
+ # true.blank? #=> false
62
+ #
63
+ # @return [FalseClass]
64
+ #
65
+ # @api public
66
+ def blank?
67
+ false
68
+ end
69
+ def present?
70
+ true
71
+ end
72
+ end # class TrueClass
73
+
74
+ class FalseClass
75
+ ##
76
+ # False is always blank.
77
+ #
78
+ # false.blank? #=> true
79
+ #
80
+ # @return [TrueClass]
81
+ #
82
+ # @api public
83
+ def blank?
84
+ true
85
+ end
86
+ def present?
87
+ false
88
+ end
89
+ end # class FalseClass
90
+
91
+ class String
92
+ ##
93
+ # Strips out whitespace then tests if the string is empty.
94
+ #
95
+ # "".blank? #=> true
96
+ # " ".blank? #=> true
97
+ # " hey ho ".blank? #=> false
98
+ #
99
+ # @return [TrueClass, FalseClass]
100
+ #
101
+ # @api public
102
+ def blank?
103
+ strip.empty?
104
+ end
105
+ def present?
106
+ ! blank?
107
+ end
108
+ end # class String
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
4
+ # All rights reserved.
5
+
6
+ # Permission is granted for use, copying, modification, distribution,
7
+ # and distribution of modified versions of this work as long as the
8
+ # above copyright notice is included.
9
+ #++
10
+
11
+ ######################################################################
12
+ # BlankSlate provides an abstract base class with no predefined
13
+ # methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
14
+ # BlankSlate is useful as a base class when writing classes that
15
+ # depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
16
+ #
17
+ class BlankSlate
18
+ class << self
19
+
20
+ # Hide the method named +name+ in the BlankSlate class. Don't
21
+ # hide +instance_eval+ or any method beginning with "__".
22
+ def hide(name)
23
+ if instance_methods.include?(name.to_s) and
24
+ name !~ /^(__|instance_eval|instance_exec)/
25
+ @hidden_methods ||= {}
26
+ @hidden_methods[name.to_sym] = instance_method(name)
27
+ undef_method name
28
+ end
29
+ end
30
+
31
+ def find_hidden_method(name)
32
+ @hidden_methods ||= {}
33
+ @hidden_methods[name] || superclass.find_hidden_method(name)
34
+ end
35
+
36
+ # Redefine a previously hidden method so that it may be called on a blank
37
+ # slate object.
38
+ def reveal(name)
39
+ hidden_method = find_hidden_method(name)
40
+ fail "Don't know how to reveal method '#{name}'" unless hidden_method
41
+ define_method(name, hidden_method)
42
+ end
43
+ end
44
+
45
+ instance_methods.each { |m| hide(m) }
46
+ end
47
+
48
+ ######################################################################
49
+ # Since Ruby is very dynamic, methods added to the ancestors of
50
+ # BlankSlate <em>after BlankSlate is defined</em> will show up in the
51
+ # list of available BlankSlate methods. We handle this by defining a
52
+ # hook in the Object and Kernel classes that will hide any method
53
+ # defined after BlankSlate has been loaded.
54
+ #
55
+ module Kernel
56
+ class << self
57
+ alias_method :blank_slate_method_added, :method_added
58
+
59
+ # Detect method additions to Kernel and remove them in the
60
+ # BlankSlate class.
61
+ def method_added(name)
62
+ result = blank_slate_method_added(name)
63
+ return result if self != Kernel
64
+ BlankSlate.hide(name)
65
+ result
66
+ end
67
+ end
68
+ end
69
+
70
+ ######################################################################
71
+ # Same as above, except in Object.
72
+ #
73
+ class Object
74
+ class << self
75
+ alias_method :blank_slate_method_added, :method_added
76
+
77
+ # Detect method additions to Object and remove them in the
78
+ # BlankSlate class.
79
+ def method_added(name)
80
+ result = blank_slate_method_added(name)
81
+ return result if self != Object
82
+ BlankSlate.hide(name)
83
+ result
84
+ end
85
+
86
+ def find_hidden_method(name)
87
+ nil
88
+ end
89
+ end
90
+ end
91
+
92
+ ######################################################################
93
+ # Also, modules included into Object need to be scanned and have their
94
+ # instance methods removed from blank slate. In theory, modules
95
+ # included into Kernel would have to be removed as well, but a
96
+ # "feature" of Ruby prevents late includes into modules from being
97
+ # exposed in the first place.
98
+ #
99
+ class Module
100
+ alias blankslate_original_append_features append_features
101
+ def append_features(mod)
102
+ result = blankslate_original_append_features(mod)
103
+ return result if mod != Object
104
+ instance_methods.each do |name|
105
+ BlankSlate.hide(name)
106
+ end
107
+ result
108
+ end
109
+ end
@@ -0,0 +1,140 @@
1
+
2
+ # ** vendored from ActiveSupport 2.3.5 **
3
+ # Hash is ordered in Ruby 1.9!
4
+ if RUBY_VERSION >= '1.9'
5
+ Dictionary = ::Hash
6
+ else
7
+ class Dictionary < Hash #:nodoc:
8
+ def initialize(*args, &block)
9
+ super
10
+ @keys = []
11
+ end
12
+
13
+ def self.[](*args)
14
+ ordered_hash = new
15
+
16
+ if (args.length == 1 && args.first.is_a?(Array))
17
+ args.first.each do |key_value_pair|
18
+ next unless (key_value_pair.is_a?(Array))
19
+ ordered_hash[key_value_pair[0]] = key_value_pair[1]
20
+ end
21
+
22
+ return ordered_hash
23
+ end
24
+
25
+ unless (args.size % 2 == 0)
26
+ raise ArgumentError.new("odd number of arguments for Hash")
27
+ end
28
+
29
+ args.each_with_index do |val, ind|
30
+ next if (ind % 2 != 0)
31
+ ordered_hash[val] = args[ind + 1]
32
+ end
33
+
34
+ ordered_hash
35
+ end
36
+
37
+ def initialize_copy(other)
38
+ super
39
+ # make a deep copy of keys
40
+ @keys = other.keys
41
+ end
42
+
43
+ def []=(key, value)
44
+ @keys << key if !has_key?(key)
45
+ super
46
+ end
47
+
48
+ def delete(key)
49
+ if has_key? key
50
+ index = @keys.index(key)
51
+ @keys.delete_at index
52
+ end
53
+ super
54
+ end
55
+
56
+ def delete_if
57
+ super
58
+ sync_keys!
59
+ self
60
+ end
61
+
62
+ def reject!
63
+ super
64
+ sync_keys!
65
+ self
66
+ end
67
+
68
+ def reject(&block)
69
+ dup.reject!(&block)
70
+ end
71
+
72
+ def keys
73
+ @keys.dup
74
+ end
75
+
76
+ def values
77
+ @keys.collect { |key| self[key] }
78
+ end
79
+
80
+ def to_hash
81
+ self
82
+ end
83
+
84
+ def to_a
85
+ @keys.map { |key| [ key, self[key] ] }
86
+ end
87
+
88
+ def each_key
89
+ @keys.each { |key| yield key }
90
+ end
91
+
92
+ def each_value
93
+ @keys.each { |key| yield self[key]}
94
+ end
95
+
96
+ def each
97
+ @keys.each {|key| yield [key, self[key]]}
98
+ end
99
+
100
+ alias_method :each_pair, :each
101
+
102
+ def clear
103
+ super
104
+ @keys.clear
105
+ self
106
+ end
107
+
108
+ def shift
109
+ k = @keys.first
110
+ v = delete(k)
111
+ [k, v]
112
+ end
113
+
114
+ def merge!(other_hash)
115
+ other_hash.each {|k,v| self[k] = v }
116
+ self
117
+ end
118
+
119
+ def merge(other_hash)
120
+ dup.merge!(other_hash)
121
+ end
122
+
123
+ # When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
124
+ def replace(other)
125
+ super
126
+ @keys = other.keys
127
+ self
128
+ end
129
+
130
+ def inspect
131
+ "#<Dictionary #{super}>"
132
+ end
133
+
134
+ private
135
+
136
+ def sync_keys!
137
+ @keys.delete_if {|k| !has_key?(k)}
138
+ end
139
+ end
140
+ end