objective_command 0.1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/AUTHORS +5 -0
  2. data/ChangeLog +17 -0
  3. data/NEWS +3 -0
  4. data/README +2 -0
  5. data/Rakefile +8 -0
  6. data/SPEC.gemspec +15 -0
  7. data/SPEC.yml +43 -0
  8. data/bin/ocmd +32 -0
  9. data/lib/hookable.rb +284 -0
  10. data/lib/hooker.rb +47 -0
  11. data/lib/objective_command/all.rb +32 -0
  12. data/lib/objective_command/commands/command.rb +535 -0
  13. data/lib/objective_command/commands/factory.rb +69 -0
  14. data/lib/objective_command/commands/pipe.rb +121 -0
  15. data/lib/objective_command/commands/seq.rb +35 -0
  16. data/lib/objective_command/datas/composite.rb +55 -0
  17. data/lib/objective_command/datas/data.rb +175 -0
  18. data/lib/objective_command/datas/factory.rb +74 -0
  19. data/lib/objective_command/datas/pipe.rb +55 -0
  20. data/lib/objective_command/datas/temp.rb +24 -0
  21. data/lib/objective_command/datas.rb +11 -0
  22. data/lib/objective_command/helpers.rb +113 -0
  23. data/lib/objective_command/runners/exec.rb +46 -0
  24. data/lib/objective_command/runners/fork.rb +91 -0
  25. data/lib/objective_command/runners/mockable.rb +62 -0
  26. data/lib/objective_command/runners/no_run.rb +44 -0
  27. data/lib/objective_command/runners/popen.rb +49 -0
  28. data/lib/objective_command/runners/runner.rb +227 -0
  29. data/lib/objective_command/runners/system.rb +54 -0
  30. data/lib/objective_command/runners.rb +11 -0
  31. data/lib/objective_command/shell.rb +173 -0
  32. data/lib/objective_command/version_id.rb +10 -0
  33. data/lib/objective_command.rb +54 -0
  34. data/test/check-objective_command.yml +10 -0
  35. data/test/check-pkg-objective_command.yml +13 -0
  36. data/test/sanity/multiple-requires.yml +62 -0
  37. data/test/sanity/single-requires.yml +40 -0
  38. data/test/sanity-suite.yml +10 -0
  39. data/test/unit-suite.yml +14 -0
  40. metadata +97 -0
data/AUTHORS ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ Commands was written by and with the assistance of:
3
+
4
+ - Nicolas Pouillard <ertai@feydakins.org>:
5
+ - Initial design
data/ChangeLog ADDED
@@ -0,0 +1,17 @@
1
+ 2005-10-05 Nicolas Pouillard <ertai@lrde.epita.fr>
2
+
3
+ Initial checkin.
4
+
5
+ * test: New.
6
+ * test/unit: New.
7
+ * test/functional: New.
8
+ * test/sanity: New.
9
+ * test/fixtures: New.
10
+ * Rakefile: New.
11
+ * AUTHORS: New.
12
+ * lib: New.
13
+ * bin: New.
14
+ * SPEC.yml: New.
15
+ * vcs: New.
16
+ * vcs/commands_vcs.rb: New.
17
+
data/NEWS ADDED
@@ -0,0 +1,3 @@
1
+ = New 0.1, 2007-01-14:
2
+
3
+ Initial Release.
data/README ADDED
@@ -0,0 +1,2 @@
1
+ Objective command is a ruby library dedicated at running commands in a OO
2
+ style and in a completly extensible way.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # Author:: The Uttk Team. -*- ruby -*-
2
+ # Copyright:: Copyright (c) 2005, 2006 Uttk team. All rights reserved.
3
+ # License:: Ruby License
4
+ # Revision:: $Id$
5
+
6
+ require 'rubygems'
7
+ require_gem 'core_ex'
8
+ load 'core_ex/rakefile_base.rf'
data/SPEC.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{objective_command}
3
+ s.version = "0.1.5.0"
4
+ s.date = %q{2007-01-14}
5
+ s.summary = %q{ObjectiveCommand}
6
+ s.email = ["ertai@feydakins.org"]
7
+ s.homepage = %q{http://api.feydakins.org/objective_command}
8
+ s.rubyforge_project = %q{objective_command}
9
+ s.description = %q{}
10
+ s.default_executable = %q{ocmd}
11
+ s.authors = ["Nicolas Pouillard"]
12
+ s.files = ["lib/hookable.rb", "lib/hooker.rb", "lib/objective_command.rb", "lib/objective_command/all.rb", "lib/objective_command/datas.rb", "lib/objective_command/helpers.rb", "lib/objective_command/runners.rb", "lib/objective_command/shell.rb", "lib/objective_command/version_id.rb", "lib/objective_command/commands/command.rb", "lib/objective_command/commands/factory.rb", "lib/objective_command/commands/pipe.rb", "lib/objective_command/commands/seq.rb", "lib/objective_command/datas/composite.rb", "lib/objective_command/datas/data.rb", "lib/objective_command/datas/factory.rb", "lib/objective_command/datas/pipe.rb", "lib/objective_command/datas/temp.rb", "lib/objective_command/runners/exec.rb", "lib/objective_command/runners/fork.rb", "lib/objective_command/runners/mockable.rb", "lib/objective_command/runners/no_run.rb", "lib/objective_command/runners/popen.rb", "lib/objective_command/runners/runner.rb", "lib/objective_command/runners/system.rb", "test/check-objective_command.yml", "test/check-pkg-objective_command.yml", "test/fixtures", "test/functional", "test/sanity", "test/sanity-suite.yml", "test/unit", "test/unit-suite.yml", "test/sanity/multiple-requires.yml", "test/sanity/single-requires.yml", "bin/ocmd", "AUTHORS", "ChangeLog", "NEWS", "Rakefile", "README", "SPEC.gemspec", "SPEC.yml"]
13
+ s.executables = ["ocmd"]
14
+ s.add_dependency(%q<core_ex>, ["~> 0.6.5"])
15
+ end
data/SPEC.yml ADDED
@@ -0,0 +1,43 @@
1
+ ---
2
+ Author: The Uttk Team
3
+ License: Ruby License
4
+ Revision: '$Id$'
5
+
6
+ version: !feydakins.org,2006/version dev-ruby/objective_command-0.1
7
+
8
+ # XXX also check lib/objective_command/version_id.rb
9
+
10
+ title: ObjectiveCommand
11
+ summary: ObjectiveCommand
12
+ description: ""
13
+ homepage: http://api.feydakins.org/objective_command
14
+
15
+ user: ertai
16
+ rubyforge_project: ttk
17
+ rubyforge_sub_package_name: objective_command
18
+
19
+ root_test_suite: test/check-pkg-objective_command.yml
20
+ rdoc_dir: doc/html
21
+ tags_url: svn://svn.feydakins.org/objective_command/tags
22
+ trunk_url: svn://svn.feydakins.org/objective_command/trunk
23
+ version_id.rb: !path lib/objective_command/version_id.rb
24
+
25
+ rdoc_files: !filelist
26
+ - README
27
+ - AUTHORS
28
+ - NEWS
29
+ - lib/**/*.rb
30
+
31
+ pkg_files: !filelist
32
+ - lib/**/*.rb
33
+ - test/**/*
34
+ - bin/**/*
35
+ - '[A-Z]*'
36
+
37
+ dependencies:
38
+ core_ex:
39
+ gem : ~> 0.6.5
40
+ tarball: http://rubyforge.iasi.roedu.net/files/ttk/core_ex-0.6.tar.gz
41
+ vcs : svn://svn.feydakins.org/ruby_ex/trunk/core_ex
42
+
43
+ uttk_version: >= 0.3.6.1
data/bin/ocmd ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ require Pathname.new(__FILE__).dirname.parent + 'lib/objective_command/all'
5
+ require 'irb'
6
+ require 'irb/completion'
7
+ singleton_class.include OCmd::Shell::MethodMissing
8
+ self.runner = OCmd::Runners::System.new
9
+ RUNNER = runner
10
+ runner.subscribe_hook(:before_return) do |_, data|
11
+ suppress(IOError) { data.display }
12
+ end
13
+ module IRB
14
+ def IRB.start_ocmd
15
+ IRB.setup(nil)
16
+ @CONF[:IRB_NAME] = 'ocmd'
17
+ if @CONF[:SCRIPT]
18
+ irb = Irb.new(nil, @CONF[:SCRIPT])
19
+ else
20
+ irb = Irb.new
21
+ end
22
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
23
+ @CONF[:MAIN_CONTEXT] = irb.context
24
+ trap("SIGINT") do
25
+ irb.signal_handle
26
+ end
27
+ catch(:IRB_EXIT) do
28
+ irb.eval_input
29
+ end
30
+ end
31
+ end
32
+ IRB.start_ocmd
data/lib/hookable.rb ADDED
@@ -0,0 +1,284 @@
1
+ # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/cmd/trunk/lib/hookable.rb 24388 2006-07-09T17:09:53.202920Z ertai $
5
+
6
+ module Hookable
7
+
8
+ module Internal
9
+ module_function
10
+ def hook_trigger hooker, name, *args, &block
11
+ if hooker.respond_to?(name)
12
+ hooker.send(name, *args, &block)
13
+ else
14
+ if hooker.respond_to? :default_hook and not hooker.default_hook.nil?
15
+ hooker.send(hooker.default_hook, name, *args, &block)
16
+ elsif hooker.respond_to? :method_missing
17
+ hooker.send(name, *args, &block)
18
+ end
19
+ end
20
+ end
21
+ end # module Internal
22
+
23
+
24
+ setup do
25
+ class_inheritable_array :hooks
26
+ class_inheritable_array :hookers
27
+ class_inheritable_array :disabled_hooks
28
+ inheritable_attributes[:hookers] = []
29
+ inheritable_attributes[:hooks] = []
30
+ inheritable_attributes[:disabled_hooks] = []
31
+ end
32
+
33
+
34
+ def hook_trigger name, *args, &block
35
+ return if defined? @disabled_hooks and @disabled_hooks.include? name
36
+ return if disabled_hooks.include? name
37
+ self.class.hook_trigger(name, *args, &block)
38
+ return unless defined? @hookers
39
+ @hookers.each do |hooker|
40
+ Internal.hook_trigger(hooker, name, *args, &block)
41
+ end
42
+ self
43
+ end
44
+
45
+
46
+ def hooker_subscribe hooker
47
+ @hookers ||= []
48
+ @hookers << hooker
49
+ self
50
+ end
51
+
52
+
53
+ def subscribe_hook *hook_names, &block
54
+ hooker_subscribe ProcHooker.new(*hook_names, &block)
55
+ end
56
+
57
+
58
+ def disable_hook *hook_names
59
+ @disabled_hooks ||= []
60
+ @disabled_hooks += hook_names
61
+ self
62
+ end
63
+
64
+
65
+ module ClassMethods
66
+
67
+ def hook_trigger name, *args, &block
68
+ raise ArgumentError, "Unknown hook #{name}" unless hooks.include? name
69
+ return if disabled_hooks.include? name
70
+ hookers.each do |hooker|
71
+ Internal.hook_trigger(hooker, name, *args, &block)
72
+ end
73
+ self
74
+ end
75
+
76
+
77
+ def hooker_subscribe hooker
78
+ self.hookers = [hooker]
79
+ self
80
+ end
81
+
82
+
83
+ def subscribe_hook *hook_names, &block
84
+ hooker_subscribe ProcHooker.new(*hook_names, &block)
85
+ end
86
+
87
+
88
+ def disable_hook *hook_names
89
+ self.disabled_hooks = hook_names
90
+ end
91
+
92
+
93
+ def hook_declare name, *groups # FIXME handle groups
94
+ self.hooks = [name]
95
+ end
96
+
97
+ end # module ClassMethods
98
+
99
+
100
+ class ProcHooker < Proc
101
+ include Hooker
102
+ def initialize *hook_names, &block
103
+ hook_method :call, *hook_names
104
+ super(&block)
105
+ end
106
+ end
107
+
108
+
109
+ end # module Hookable
110
+
111
+
112
+
113
+ test_section __FILE__ do
114
+
115
+ class HookableHookerTest < Test::Unit::TestCase
116
+
117
+ class HookerTest
118
+ include Hooker
119
+
120
+ attr_reader :stack
121
+
122
+ def log *args
123
+ @stack ||= []
124
+ @stack << args
125
+ end
126
+
127
+ def method_missing *a
128
+ log(:method_missing, *a)
129
+ end
130
+
131
+ def hook1 *a
132
+ log(:hook1, *a)
133
+ end
134
+
135
+ def reset
136
+ @stack.clear if defined? @stack and @stack
137
+ end
138
+ end
139
+
140
+
141
+ STATIC_HOOKER_TEST = HookerTest.new
142
+
143
+
144
+ class HookableTest
145
+ include Hookable
146
+
147
+ hook_declare :hook1
148
+
149
+ hook_declare :hook2, :group1
150
+
151
+ def run
152
+ run1
153
+ run2
154
+ end
155
+
156
+ def run1
157
+ hook_trigger :hook1
158
+ end
159
+
160
+ def run2
161
+ hook_trigger :hook2, 42
162
+ suppress(ArgumentError) { hook_trigger :hook3 }
163
+ end
164
+
165
+ def << hooker
166
+ hooker_subscribe hooker
167
+ end
168
+
169
+ hooker_subscribe STATIC_HOOKER_TEST
170
+
171
+ def self.ref
172
+ [
173
+ [[:hook1], [:method_missing, :hook2, 42]],
174
+ [[:hook1], [:default, :hook2, 42]],
175
+ [[:hook_1_and_2], [:hook_1_and_2, 42]],
176
+ [[:hook1], [:method_missing, :default_by_method_missing, :hook2, 42]],
177
+ [[:hook1], [:hook2, 42]],
178
+ [[:hook1], [:method_missing, :hook2_by_dynamic_hook_method, 42]]
179
+ ]
180
+ end
181
+
182
+ end
183
+
184
+
185
+
186
+ class SubHookableTest < HookableTest
187
+ hook_declare :hook3
188
+
189
+ def self.ref
190
+ [
191
+ [[:hook1], [:method_missing, :hook2, 42], [:method_missing, :hook3]],
192
+ [[:hook1], [:default, :hook2, 42], [:default, :hook3]],
193
+ [[:hook_1_and_2], [:hook_1_and_2, 42], [:method_missing, :hook3]],
194
+ [[:hook1], [:method_missing, :default_by_method_missing, :hook2, 42],
195
+ [:method_missing, :default_by_method_missing, :hook3]],
196
+ [[:hook1], [:hook2, 42], [:default, :hook3]],
197
+ [[:hook1], [:method_missing, :hook2_by_dynamic_hook_method, 42],
198
+ [:method_missing, :hook3]]
199
+ ]
200
+ end
201
+
202
+ end
203
+
204
+
205
+
206
+ class HookerTest1 < HookerTest
207
+ def default *a
208
+ log(:default, *a)
209
+ end
210
+ hook_default_method :default
211
+ end
212
+
213
+
214
+
215
+ class HookerTest2 < HookerTest
216
+ def hook_1_and_2 *a
217
+ log(:hook_1_and_2, *a)
218
+ end
219
+ hook_method :hook_1_and_2, :hook1, :hook2
220
+ end
221
+
222
+
223
+
224
+ class HookerTest3 < HookerTest
225
+ hook_default_method :default_by_method_missing
226
+ end
227
+
228
+
229
+
230
+ class HookerTest4 < HookerTest
231
+ end
232
+
233
+
234
+
235
+ class HookerTest21 < HookerTest1
236
+ def hook2 ( *a )
237
+ log(:hook2, *a)
238
+ end
239
+ end
240
+
241
+
242
+
243
+ def test_hookable
244
+ hookable_checker HookableTest.new
245
+ end
246
+
247
+
248
+
249
+ def test_sub_hookable
250
+ hookable_checker SubHookableTest.new
251
+ end
252
+
253
+
254
+
255
+ def hookable_checker support
256
+ hookers = []
257
+ hookers << HookerTest1.new
258
+ hookers << HookerTest2.new
259
+ hookers << HookerTest3.new
260
+ hookers << HookerTest21.new
261
+ hooker4 = HookerTest4.new
262
+ hookers << hooker4
263
+ hookers.each do |hooker|
264
+ support << hooker
265
+ end
266
+ STATIC_HOOKER_TEST.reset
267
+ hookers.unshift STATIC_HOOKER_TEST
268
+ hooker4.hook_method(:hook2_by_dynamic_hook_method, :hook2)
269
+ @a = []
270
+ support.subscribe_hook(:hook2) do |*a|
271
+ assert_nothing_raised do
272
+ @a << [:proc_hooker_call, :hook2, *a]
273
+ end
274
+ end
275
+ support.run
276
+ hookers.zip(support.class.ref).each do |hooker, ref|
277
+ assert_equal(ref, hooker.stack)
278
+ end
279
+ assert_equal([[:proc_hooker_call, :hook2, 42]], @a)
280
+ end
281
+
282
+ end
283
+
284
+ end
data/lib/hooker.rb ADDED
@@ -0,0 +1,47 @@
1
+ # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: /w/fey/cmd/trunk/lib/hooker.rb 24388 2006-07-09T17:09:53.202920Z ertai $
5
+
6
+ module Hooker
7
+
8
+ setup do
9
+ class_inheritable_accessor :default_hook
10
+ end
11
+
12
+ def hook_method method, *hook_names
13
+ raise unless method.is_a? Symbol
14
+ hook_names.each do |hook_name|
15
+ raise unless hook_name.is_a? Symbol
16
+ instance_eval %Q{
17
+ def #{hook_name} ( *a, &b )
18
+ #{method}(*a, &b)
19
+ end
20
+ }
21
+ end
22
+ end
23
+
24
+ module ClassMethods
25
+
26
+ def hook_default_method method
27
+ raise unless method.is_a? Symbol
28
+ self.default_hook = method
29
+ end
30
+
31
+
32
+ def hook_method method, *hook_names
33
+ raise unless method.is_a? Symbol
34
+ hook_names.each do |hook_name|
35
+ raise unless hook_name.is_a? Symbol
36
+ module_eval %Q{
37
+ def #{hook_name} ( *a, &b )
38
+ #{method}(*a, &b)
39
+ end
40
+ }
41
+ end
42
+ end
43
+
44
+ end # module ClassMethods
45
+
46
+ end # module Hooker
47
+
@@ -0,0 +1,32 @@
1
+ module ObjectiveCommand
2
+ module Helpers
3
+ end
4
+ module All
5
+ end
6
+ end
7
+ unless embedded_test_mode?
8
+ $: << File.dirname(File.dirname(__FILE__))
9
+ require 'objective_command'
10
+ require 'hookable'
11
+ require 'hooker'
12
+ require 'objective_command/runners/runner'
13
+ require 'objective_command/runners/exec'
14
+ require 'objective_command/runners/fork'
15
+ require 'objective_command/runners/system'
16
+ require 'objective_command/runners/popen'
17
+ require 'objective_command/runners/mockable'
18
+ require 'objective_command/runners/no_run'
19
+ require 'objective_command/runners'
20
+ require 'objective_command/datas/data'
21
+ require 'objective_command/datas/temp'
22
+ require 'objective_command/datas/factory'
23
+ require 'objective_command/datas/composite'
24
+ require 'objective_command/datas/pipe'
25
+ require 'objective_command/datas'
26
+ require 'objective_command/helpers'
27
+ require 'objective_command/shell'
28
+ require 'objective_command/commands/command'
29
+ require 'objective_command/commands/factory'
30
+ require 'objective_command/commands/pipe'
31
+ require 'objective_command/commands/seq'
32
+ end