silk 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ begin
17
17
  gem.add_dependency 'sinatra'
18
18
  gem.add_dependency 'SyslogLogger'
19
19
 
20
- gem.add_development_dependency "thoughtbot-shoulda"
20
+ gem.add_development_dependency "shoulda"
21
21
  gem.add_development_dependency "rack-test"
22
22
  gem.add_development_dependency "redgreen"
23
23
  gem.add_development_dependency "mocha"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -7,7 +7,6 @@ require 'daemons'
7
7
  require 'options'
8
8
  require 'server'
9
9
  require 'tasks'
10
- require 'dsl'
11
10
 
12
11
  module Silk
13
12
  def self.run
@@ -0,0 +1,131 @@
1
+ require 'rexml/document'
2
+
3
+ class FormattedResponse
4
+ def method_missing(symbol, *args, &blk)
5
+ if [ :json, :xml, :text ].include?(symbol)
6
+ if block_given?
7
+ instance_variable_set("@#{symbol.to_s}", yield)
8
+ else
9
+ instance_variable_get("@#{symbol.to_s}")
10
+ end
11
+ else
12
+ super
13
+ end
14
+ end
15
+ end
16
+
17
+ class ProcessResult
18
+ attr_accessor :stdout, :stderr, :exitstatus
19
+
20
+ def initialize(stdout, stderr, exitstatus)
21
+ @stdout = stdout
22
+ @stderr = stderr
23
+ @exitstatus = exitstatus
24
+ end
25
+
26
+ def to_json
27
+ {
28
+ :stdout => self.stdout,
29
+ :stderr => self.stderr,
30
+ :exitstatus => self.exitstatus
31
+ }.to_json
32
+ end
33
+
34
+ def to_xml
35
+ doc = REXML::Document.new
36
+ doc.add(REXML::XMLDecl.new)
37
+ result = REXML::Element.new('process_result')
38
+
39
+ stdOutEl = REXML::Element.new('stdout')
40
+ stdOutEl.add_text(self.stdout.to_s)
41
+
42
+ stdErrEl = REXML::Element.new('stderr')
43
+ stdErrEl.add_text(self.stderr.to_s)
44
+
45
+ exitStatusEl = REXML::Element.new('exitstatus')
46
+ exitStatusEl.add_text(self.exitstatus.to_s)
47
+
48
+ result.add_element(stdOutEl)
49
+ result.add_element(stdErrEl)
50
+ result.add_element(exitStatusEl)
51
+
52
+ doc.add(result);
53
+ doc.to_s
54
+ end
55
+
56
+ def to_s
57
+ self.stdout || self.stderr
58
+ end
59
+ end
60
+
61
+ # Allows you to set different outputs based on the requested format.
62
+ # Supports xml, json and text
63
+ #
64
+ # respond_to do |format|
65
+ # format.xml { '<xml>xml</xml>' }
66
+ # format.json { '{ json }' }
67
+ # format.text { 'text' }
68
+ # end
69
+ #
70
+ def respond_to(&blk)
71
+ response = FormattedResponse.new
72
+ yield(response)
73
+ case(ENV['format'])
74
+ when 'xml'
75
+ puts response.xml
76
+ when 'json'
77
+ puts response.json
78
+ else
79
+ puts response.text
80
+ end
81
+ end
82
+
83
+ # Allows you to set different error outputs based on the requested format.
84
+ # SUpports xml, json and text
85
+ #
86
+ # error_respond_to do |format|
87
+ # format.xml { '<xml>xml</xml>' }
88
+ # format.json { '{ json }' }
89
+ # format.text { 'text' }
90
+ # end
91
+ #
92
+ def error_respond_to(&blk)
93
+ response = FormattedResponse.new
94
+ yield(response)
95
+ case(ENV['format'])
96
+ when 'xml'
97
+ $stderr.puts response.xml
98
+ when 'json'
99
+ $stderr.puts response.json
100
+ else
101
+ $stderr.puts response.text
102
+ end
103
+ end
104
+
105
+ def run(command)
106
+ stdout_read, stdout_write = IO.pipe
107
+ stderr_read, stderr_write = IO.pipe
108
+
109
+ pid = Process.fork do
110
+ $stdout.reopen stdout_write
111
+ $stderr.reopen stderr_write
112
+ stdout_read.close
113
+ stderr_read.close
114
+ Kernel.exec command
115
+ end
116
+
117
+ stdout_write.close
118
+ stderr_write.close
119
+
120
+ stdout = ''
121
+ stdout_read.each do |line|
122
+ stdout += line
123
+ end
124
+ stderr = ''
125
+ stderr_read.each do |line|
126
+ stderr += line
127
+ end
128
+ pid, status = Process.waitpid2(pid)
129
+
130
+ return ProcessResult.new(stdout, stderr, status.exitstatus)
131
+ end
@@ -55,7 +55,7 @@ class Options
55
55
  File.open(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')) do |fh|
56
56
  puts fh.read
57
57
  end
58
- exit(0)
58
+ exit(1)
59
59
  end
60
60
  end
61
61
 
@@ -64,7 +64,7 @@ class Options
64
64
  options
65
65
  rescue OptionParser::InvalidOption => e
66
66
  puts optparse
67
- exit(-1)
67
+ exit(1)
68
68
  end
69
69
  end
70
70
  end
@@ -6,6 +6,8 @@ module Silk
6
6
  Rake::Task.clear
7
7
  @app = Rake::Application.new
8
8
  @app.init
9
+ @app.rake_require 'dsl'
10
+
9
11
  Silk.options[:recipe_paths].each do |path|
10
12
  FileList.new("#{path}/*.rake").each do |file|
11
13
  @app.add_import(file)
@@ -19,7 +21,8 @@ module Silk
19
21
  end
20
22
 
21
23
  def run(task, arguments = {})
22
- Rake::Task[task].execute(arguments)
24
+ task = Rake::Task[task]
25
+ task.execute(arguments)
23
26
  end
24
27
  end
25
28
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{silk}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Myles Eftos"]
12
- s.date = %q{2010-08-28}
12
+ s.date = %q{2010-08-29}
13
13
  s.default_executable = %q{silk}
14
14
  s.description = %q{It allows you to write rake tasks to do common tasks, such as creating email addresses, adding users etc. Silk provides a HTTP wrapper the the rake tasks, and allows communication via JSON objects, which makes it dead easy for them to be called from a web app.}
15
15
  s.email = %q{myles@madpilot.com.au}
@@ -28,11 +28,13 @@ Gem::Specification.new do |s|
28
28
  "bin/silk",
29
29
  "install.rb",
30
30
  "lib/silk.rb",
31
- "lib/silk/dsl.rb",
31
+ "lib/silk/dsl.rake",
32
32
  "lib/silk/options.rb",
33
33
  "lib/silk/server.rb",
34
34
  "lib/silk/tasks.rb",
35
35
  "silk.gemspec",
36
+ "test/bin/failure",
37
+ "test/bin/successful",
36
38
  "test/helper.rb",
37
39
  "test/rakefiles/test.rake",
38
40
  "test/test_dsl.rb",
@@ -45,28 +47,28 @@ Gem::Specification.new do |s|
45
47
  s.homepage = %q{http://github.com/madpilot/silk}
46
48
  s.rdoc_options = ["--charset=UTF-8"]
47
49
  s.require_paths = ["lib"]
48
- s.rubygems_version = %q{1.3.5}
50
+ s.rubygems_version = %q{1.3.7}
49
51
  s.summary = %q{A framework for creating a hosting console}
50
52
  s.test_files = [
51
- "test/test_server.rb",
52
- "test/test_silk.rb",
53
- "test/test_options.rb",
53
+ "test/helper.rb",
54
54
  "test/test_dsl.rb",
55
- "test/test_tasks.rb",
56
55
  "test/test_helper.rb",
57
- "test/helper.rb"
56
+ "test/test_options.rb",
57
+ "test/test_server.rb",
58
+ "test/test_silk.rb",
59
+ "test/test_tasks.rb"
58
60
  ]
59
61
 
60
62
  if s.respond_to? :specification_version then
61
63
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
62
64
  s.specification_version = 3
63
65
 
64
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
66
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
67
  s.add_runtime_dependency(%q<daemons>, [">= 0"])
66
68
  s.add_runtime_dependency(%q<json>, [">= 0"])
67
69
  s.add_runtime_dependency(%q<sinatra>, [">= 0"])
68
70
  s.add_runtime_dependency(%q<SyslogLogger>, [">= 0"])
69
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
71
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
70
72
  s.add_development_dependency(%q<rack-test>, [">= 0"])
71
73
  s.add_development_dependency(%q<redgreen>, [">= 0"])
72
74
  s.add_development_dependency(%q<mocha>, [">= 0"])
@@ -75,7 +77,7 @@ Gem::Specification.new do |s|
75
77
  s.add_dependency(%q<json>, [">= 0"])
76
78
  s.add_dependency(%q<sinatra>, [">= 0"])
77
79
  s.add_dependency(%q<SyslogLogger>, [">= 0"])
78
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
80
+ s.add_dependency(%q<shoulda>, [">= 0"])
79
81
  s.add_dependency(%q<rack-test>, [">= 0"])
80
82
  s.add_dependency(%q<redgreen>, [">= 0"])
81
83
  s.add_dependency(%q<mocha>, [">= 0"])
@@ -85,7 +87,7 @@ Gem::Specification.new do |s|
85
87
  s.add_dependency(%q<json>, [">= 0"])
86
88
  s.add_dependency(%q<sinatra>, [">= 0"])
87
89
  s.add_dependency(%q<SyslogLogger>, [">= 0"])
88
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
90
+ s.add_dependency(%q<shoulda>, [">= 0"])
89
91
  s.add_dependency(%q<rack-test>, [">= 0"])
90
92
  s.add_dependency(%q<redgreen>, [">= 0"])
91
93
  s.add_dependency(%q<mocha>, [">= 0"])
@@ -0,0 +1,3 @@
1
+ #!/bin/env ruby
2
+ $stderr.puts "Fail :("
3
+ exit(1)
@@ -0,0 +1,3 @@
1
+ #!/bin/env ruby
2
+ puts "Success!"
3
+ exit(0)
@@ -1,7 +1,54 @@
1
1
  require 'test_helper'
2
2
 
3
+ # Need some helper classes so we can call the methods defined in the rake include file
4
+ eval <<-EOF
5
+ module Silk
6
+ module DSL
7
+ #{File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'silk', 'dsl.rake')))}
8
+ end
9
+ end
10
+ EOF
11
+
12
+ class FakeRake
13
+ include Silk::DSL
14
+ end
15
+
3
16
  class TestDSL < Test::Unit::TestCase
4
17
  context 'TestDSL' do
18
+ setup do
19
+ @context = FakeRake.new
20
+ end
21
+
22
+ context 'ProcessResult' do
23
+ setup do
24
+ @result = Silk::DSL::ProcessResult.new('Standard Output', 'Standard Error', 0)
25
+ end
26
+
27
+ context 'to_xml' do
28
+ should 'return an XML representation of the object'
29
+ end
30
+
31
+ context 'to_json' do
32
+ should 'return an JSON respresentation of the object' do
33
+ obj = JSON::parse(@result.to_json)
34
+ assert_equal 'Standard Output', obj['stdout']
35
+ assert_equal 'Standard Error', obj['stderr']
36
+ assert_equal 0, obj['exitstatus']
37
+ end
38
+ end
39
+
40
+ context 'to_s' do
41
+ should 'return stdout if defined' do
42
+ assert_equal 'Standard Output', @result.to_s
43
+ end
44
+
45
+ should 'return stderr if stdout if not defined' do
46
+ @result.stdout = nil
47
+ assert_equal 'Standard Error', @result.to_s
48
+ end
49
+ end
50
+ end
51
+
5
52
  context 'respond_to' do
6
53
  should 'call the text block if ENV[format] == text' do
7
54
  ENV['format'] = 'text'
@@ -11,7 +58,7 @@ class TestDSL < Test::Unit::TestCase
11
58
  $stdout.reopen stdout_write
12
59
  stdout_read.close
13
60
 
14
- respond_to do |format|
61
+ @context.respond_to do |format|
15
62
  format.text { 'text' }
16
63
  format.json { 'json'.to_json }
17
64
  format.xml { '<xml>xml</xml>' }
@@ -35,7 +82,7 @@ class TestDSL < Test::Unit::TestCase
35
82
  $stdout.reopen stdout_write
36
83
  stdout_read.close
37
84
 
38
- respond_to do |format|
85
+ @context.respond_to do |format|
39
86
  format.text { 'text' }
40
87
  format.json { 'json'.to_json }
41
88
  format.xml { '<xml>xml</xml>' }
@@ -59,7 +106,7 @@ class TestDSL < Test::Unit::TestCase
59
106
  $stdout.reopen stdout_write
60
107
  stdout_read.close
61
108
 
62
- respond_to do |format|
109
+ @context.respond_to do |format|
63
110
  format.text { 'text' }
64
111
  format.json { 'json'.to_json }
65
112
  format.xml { '<xml>xml</xml>' }
@@ -85,7 +132,7 @@ class TestDSL < Test::Unit::TestCase
85
132
  $stderr.reopen stderr_write
86
133
  stderr_read.close
87
134
 
88
- error_respond_to do |format|
135
+ @context.error_respond_to do |format|
89
136
  format.text { 'text' }
90
137
  format.json { 'json'.to_json }
91
138
  format.xml { '<xml>xml</xml>' }
@@ -109,7 +156,8 @@ class TestDSL < Test::Unit::TestCase
109
156
  $stderr.reopen stderr_write
110
157
  stderr_read.close
111
158
 
112
- error_respond_to do |format|
159
+
160
+ @context.error_respond_to do |format|
113
161
  format.text { 'text' }
114
162
  format.json { 'json'.to_json }
115
163
  format.xml { '<xml>xml</xml>' }
@@ -133,7 +181,7 @@ class TestDSL < Test::Unit::TestCase
133
181
  $stderr.reopen stderr_write
134
182
  stderr_read.close
135
183
 
136
- error_respond_to do |format|
184
+ @context.error_respond_to do |format|
137
185
  format.text { 'text' }
138
186
  format.json { 'json'.to_json }
139
187
  format.xml { '<xml>xml</xml>' }
@@ -149,5 +197,27 @@ class TestDSL < Test::Unit::TestCase
149
197
  assert_equal 'json'.to_json, stderr.strip
150
198
  end
151
199
  end
200
+
201
+ context 'run' do
202
+ should 'capture standard input and return a ProcessResult object' do
203
+ result = @context.run File.join(File.dirname(__FILE__), '..', 'test', 'bin', 'successful')
204
+ assert_equal Silk::DSL::ProcessResult, result.class
205
+ end
206
+
207
+ should 'set the stdout value' do
208
+ result = @context.run File.join(File.dirname(__FILE__), '..', 'test', 'bin', 'successful')
209
+ assert_equal 'Success!', result.stdout.strip
210
+ end
211
+
212
+ should 'set the stdout value' do
213
+ result = @context.run File.join(File.dirname(__FILE__), '..', 'test', 'bin', 'failure')
214
+ assert_equal 'Fail :(', result.stderr.strip
215
+ end
216
+
217
+ should 'set the exitstatus value' do
218
+ result = @context.run File.join(File.dirname(__FILE__), '..', 'test', 'bin', 'failure')
219
+ assert_equal 1, result.exitstatus
220
+ end
221
+ end
152
222
  end
153
223
  end
@@ -89,7 +89,7 @@ class TestOptions < Test::Unit::TestCase
89
89
  assert_equal [ '/etc/silk', '/home/john/.silk', '/tmp/recipes', '/tmp/recipes_2' ], options[:recipe_paths]
90
90
  end
91
91
 
92
- should 'add recipes to the recipe list for each -r' do
92
+ should 'add recipes to the recipe list for each --recipes' do
93
93
  ARGV << '--recipes'
94
94
  ARGV << '/tmp/recipes'
95
95
  options = Options.parse
@@ -151,7 +151,7 @@ class TestOptions < Test::Unit::TestCase
151
151
  assert_equal [ 'iis' ], options[:server]
152
152
  end
153
153
 
154
- should 'set the server array if -s is set' do
154
+ should 'set the server array if --server is set' do
155
155
  ARGV << '--server'
156
156
  ARGV << 'iis'
157
157
  options = Options.parse
@@ -168,13 +168,23 @@ class TestOptions < Test::Unit::TestCase
168
168
  stdout_read.close
169
169
  options = Options.parse
170
170
  end
171
-
171
+
172
+ result = ''
172
173
  stdout_write.close
174
+ stdout_read.each do |line|
175
+ result += line
176
+ end
173
177
  pid, status = Process.waitpid2(pid)
174
- assert_equal -1, status.exitstatus
178
+ assert_equal 1, status.exitstatus
179
+ version = ''
180
+
181
+ File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')) do |fh|
182
+ version = fh.read
183
+ end
184
+ assert_equal result, version
175
185
  end
176
186
 
177
- should 'display the VERSION of -v is set' do
187
+ should 'display the VERSION of --version is set' do
178
188
  ARGV << '--version'
179
189
 
180
190
  stdout_read, stdout_write = IO.pipe
@@ -191,7 +201,8 @@ class TestOptions < Test::Unit::TestCase
191
201
  result += line
192
202
  end
193
203
  pid, status = Process.waitpid2(pid)
194
- assert_equal 0, status.exitstatus
204
+ assert_equal 1, status.exitstatus
205
+
195
206
  version = ''
196
207
  File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')) do |fh|
197
208
  version = fh.read
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 4
10
+ version: 0.0.4
5
11
  platform: ruby
6
12
  authors:
7
13
  - Myles Eftos
@@ -9,89 +15,121 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-08-28 00:00:00 +08:00
18
+ date: 2010-08-29 00:00:00 +08:00
13
19
  default_executable: silk
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: daemons
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
23
32
  version: "0"
24
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: json
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
30
40
  requirements:
31
41
  - - ">="
32
42
  - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
33
46
  version: "0"
34
- version:
47
+ type: :runtime
48
+ version_requirements: *id002
35
49
  - !ruby/object:Gem::Dependency
36
50
  name: sinatra
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
40
54
  requirements:
41
55
  - - ">="
42
56
  - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
43
60
  version: "0"
44
- version:
61
+ type: :runtime
62
+ version_requirements: *id003
45
63
  - !ruby/object:Gem::Dependency
46
64
  name: SyslogLogger
47
- type: :runtime
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
50
68
  requirements:
51
69
  - - ">="
52
70
  - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
53
74
  version: "0"
54
- version:
75
+ type: :runtime
76
+ version_requirements: *id004
55
77
  - !ruby/object:Gem::Dependency
56
- name: thoughtbot-shoulda
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
78
+ name: shoulda
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
60
82
  requirements:
61
83
  - - ">="
62
84
  - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
63
88
  version: "0"
64
- version:
89
+ type: :development
90
+ version_requirements: *id005
65
91
  - !ruby/object:Gem::Dependency
66
92
  name: rack-test
67
- type: :development
68
- version_requirement:
69
- version_requirements: !ruby/object:Gem::Requirement
93
+ prerelease: false
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
70
96
  requirements:
71
97
  - - ">="
72
98
  - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
73
102
  version: "0"
74
- version:
103
+ type: :development
104
+ version_requirements: *id006
75
105
  - !ruby/object:Gem::Dependency
76
106
  name: redgreen
77
- type: :development
78
- version_requirement:
79
- version_requirements: !ruby/object:Gem::Requirement
107
+ prerelease: false
108
+ requirement: &id007 !ruby/object:Gem::Requirement
109
+ none: false
80
110
  requirements:
81
111
  - - ">="
82
112
  - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
83
116
  version: "0"
84
- version:
117
+ type: :development
118
+ version_requirements: *id007
85
119
  - !ruby/object:Gem::Dependency
86
120
  name: mocha
87
- type: :development
88
- version_requirement:
89
- version_requirements: !ruby/object:Gem::Requirement
121
+ prerelease: false
122
+ requirement: &id008 !ruby/object:Gem::Requirement
123
+ none: false
90
124
  requirements:
91
125
  - - ">="
92
126
  - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
93
130
  version: "0"
94
- version:
131
+ type: :development
132
+ version_requirements: *id008
95
133
  description: It allows you to write rake tasks to do common tasks, such as creating email addresses, adding users etc. Silk provides a HTTP wrapper the the rake tasks, and allows communication via JSON objects, which makes it dead easy for them to be called from a web app.
96
134
  email: myles@madpilot.com.au
97
135
  executables:
@@ -111,11 +149,13 @@ files:
111
149
  - bin/silk
112
150
  - install.rb
113
151
  - lib/silk.rb
114
- - lib/silk/dsl.rb
152
+ - lib/silk/dsl.rake
115
153
  - lib/silk/options.rb
116
154
  - lib/silk/server.rb
117
155
  - lib/silk/tasks.rb
118
156
  - silk.gemspec
157
+ - test/bin/failure
158
+ - test/bin/successful
119
159
  - test/helper.rb
120
160
  - test/rakefiles/test.rake
121
161
  - test/test_dsl.rb
@@ -134,29 +174,35 @@ rdoc_options:
134
174
  require_paths:
135
175
  - lib
136
176
  required_ruby_version: !ruby/object:Gem::Requirement
177
+ none: false
137
178
  requirements:
138
179
  - - ">="
139
180
  - !ruby/object:Gem::Version
181
+ hash: 3
182
+ segments:
183
+ - 0
140
184
  version: "0"
141
- version:
142
185
  required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
143
187
  requirements:
144
188
  - - ">="
145
189
  - !ruby/object:Gem::Version
190
+ hash: 3
191
+ segments:
192
+ - 0
146
193
  version: "0"
147
- version:
148
194
  requirements: []
149
195
 
150
196
  rubyforge_project:
151
- rubygems_version: 1.3.5
197
+ rubygems_version: 1.3.7
152
198
  signing_key:
153
199
  specification_version: 3
154
200
  summary: A framework for creating a hosting console
155
201
  test_files:
202
+ - test/helper.rb
203
+ - test/test_dsl.rb
204
+ - test/test_helper.rb
205
+ - test/test_options.rb
156
206
  - test/test_server.rb
157
207
  - test/test_silk.rb
158
- - test/test_options.rb
159
- - test/test_dsl.rb
160
208
  - test/test_tasks.rb
161
- - test/test_helper.rb
162
- - test/helper.rb
@@ -1,57 +0,0 @@
1
- class FormattedResponse
2
- def method_missing(symbol, *args, &blk)
3
- if [ :json, :xml, :text ].include?(symbol)
4
- if block_given?
5
- instance_variable_set("@#{symbol.to_s}", yield)
6
- else
7
- instance_variable_get("@#{symbol.to_s}")
8
- end
9
- else
10
- super
11
- end
12
- end
13
- end
14
-
15
- # Allows you to set different outputs based on the requested format.
16
- # SUpports xml, json and text
17
- #
18
- # respond_to do |format|
19
- # format.xml { '<xml>xml</xml>' }
20
- # format.json { '{ json }' }
21
- # format.text { 'text' }
22
- # end
23
- #
24
- def respond_to(&blk)
25
- response = FormattedResponse.new
26
- yield(response)
27
- case(ENV['format'])
28
- when 'xml'
29
- puts response.xml
30
- when 'json'
31
- puts response.json
32
- else
33
- puts response.text
34
- end
35
- end
36
-
37
- # Allows you to set different error outputs based on the requested format.
38
- # SUpports xml, json and text
39
- #
40
- # error_respond_to do |format|
41
- # format.xml { '<xml>xml</xml>' }
42
- # format.json { '{ json }' }
43
- # format.text { 'text' }
44
- # end
45
- #
46
- def error_respond_to(&blk)
47
- response = FormattedResponse.new
48
- yield(response)
49
- case(ENV['format'])
50
- when 'xml'
51
- $stderr.puts response.xml
52
- when 'json'
53
- $stderr.puts response.json
54
- else
55
- $stderr.puts response.text
56
- end
57
- end