auser-butterfly 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +24 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +48 -0
- data/Rakefile +28 -0
- data/bin/flutter +4 -0
- data/butterfly.gemspec +41 -0
- data/examples/example.json +1 -0
- data/examples/example.yml +7 -0
- data/lib/butterfly.rb +34 -0
- data/lib/butterfly/adaptor_base.rb +47 -0
- data/lib/butterfly/adaptors/json_file_adaptor.rb +33 -0
- data/lib/butterfly/adaptors/yaml_file_adaptor.rb +33 -0
- data/lib/butterfly/core/string.rb +5 -0
- data/lib/butterfly/default.rb +20 -0
- data/lib/butterfly/request.rb +20 -0
- data/lib/butterfly/response.rb +49 -0
- data/lib/butterfly/server.rb +43 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_butterfly_request.rb +24 -0
- data/test/test_butterfly_server.rb +16 -0
- data/test/test_helper.rb +6 -0
- metadata +102 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
bin/flutter
|
7
|
+
butterfly.gemspec
|
8
|
+
examples/example.json
|
9
|
+
examples/example.yml
|
10
|
+
lib/butterfly.rb
|
11
|
+
lib/butterfly/adaptor_base.rb
|
12
|
+
lib/butterfly/adaptors/json_file_adaptor.rb
|
13
|
+
lib/butterfly/adaptors/yaml_file_adaptor.rb
|
14
|
+
lib/butterfly/core/string.rb
|
15
|
+
lib/butterfly/default.rb
|
16
|
+
lib/butterfly/request.rb
|
17
|
+
lib/butterfly/response.rb
|
18
|
+
lib/butterfly/server.rb
|
19
|
+
script/console
|
20
|
+
script/destroy
|
21
|
+
script/generate
|
22
|
+
test/test_butterfly_request.rb
|
23
|
+
test/test_butterfly_server.rb
|
24
|
+
test/test_helper.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= Butterfly
|
2
|
+
|
3
|
+
http://blog.xnot.org
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
An HTTP mini server to query against modular adaptors
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
It's new
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
Check out the tests
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* thin
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* sudo gem install auser-butterfly
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2009 Ari Lerner, CloudTeam, AT&Ti
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/butterfly'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('butterfly', Butterfly::VERSION) do |p|
|
7
|
+
p.developer('Ari Lerner', 'arilerner@mac.com')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
+
p.rubyforge_name = p.name # TODO this is default value
|
11
|
+
# p.extra_deps = [
|
12
|
+
# ['activesupport','>= 2.0.2'],
|
13
|
+
# ]
|
14
|
+
p.extra_dev_deps = [
|
15
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
16
|
+
]
|
17
|
+
|
18
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
19
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
20
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
21
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
25
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
26
|
+
|
27
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
28
|
+
# task :default => [:spec, :features]
|
data/bin/flutter
ADDED
data/butterfly.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{butterfly}
|
5
|
+
s.version = "0.0.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Ari Lerner"]
|
9
|
+
s.date = %q{2009-04-03}
|
10
|
+
s.default_executable = %q{flutter}
|
11
|
+
s.description = %q{An HTTP mini server to query against modular adaptors}
|
12
|
+
s.email = ["arilerner@mac.com"]
|
13
|
+
s.executables = ["flutter"]
|
14
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
|
15
|
+
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "bin/flutter", "butterfly.gemspec", "examples/example.json", "examples/example.yml", "lib/butterfly.rb", "lib/butterfly/adaptor_base.rb", "lib/butterfly/adaptors/json_file_adaptor.rb", "lib/butterfly/adaptors/yaml_file_adaptor.rb", "lib/butterfly/core/string.rb", "lib/butterfly/default.rb", "lib/butterfly/request.rb", "lib/butterfly/response.rb", "lib/butterfly/server.rb", "script/console", "script/destroy", "script/generate", "test/test_butterfly_request.rb", "test/test_butterfly_server.rb", "test/test_helper.rb"]
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = %q{http://blog.xnot.org}
|
18
|
+
s.post_install_message = %q{PostInstall.txt}
|
19
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.rubyforge_project = %q{butterfly}
|
22
|
+
s.rubygems_version = %q{1.3.1}
|
23
|
+
s.summary = %q{An HTTP mini server to query against modular adaptors}
|
24
|
+
s.test_files = ["test/test_butterfly_request.rb", "test/test_butterfly_server.rb", "test/test_helper.rb"]
|
25
|
+
|
26
|
+
if s.respond_to? :specification_version then
|
27
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
28
|
+
s.specification_version = 2
|
29
|
+
|
30
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
31
|
+
s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
|
32
|
+
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
35
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
36
|
+
end
|
37
|
+
else
|
38
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
39
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"server" : {"name" : "maggie", "winner" : "false", "poolparty" : {"the":"boss"}}}
|
data/lib/butterfly.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
module Butterfly
|
5
|
+
VERSION = '0.0.2' unless Butterfly.const_defined?("VERSION")
|
6
|
+
|
7
|
+
def self.reload!
|
8
|
+
@reloading = true
|
9
|
+
butterfly_file = __FILE__
|
10
|
+
$LOADED_FEATURES.delete(butterfly_file)
|
11
|
+
::Kernel.load butterfly_file
|
12
|
+
@reloading = false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Hash
|
17
|
+
def method_missing(m,*a,&block)
|
18
|
+
if has_key?(m)
|
19
|
+
self[m]
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
%w(rubygems thin dslify).each do |lib|
|
27
|
+
require lib
|
28
|
+
end
|
29
|
+
|
30
|
+
%w(string).each {|lib| require "#{File.dirname(__FILE__)}/butterfly/core/#{lib}" }
|
31
|
+
|
32
|
+
%w(default adaptor_base response request server).each do |lib|
|
33
|
+
require "#{File.dirname(__FILE__)}/butterfly/#{lib}"
|
34
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Butterfly
|
2
|
+
class AdaptorBase
|
3
|
+
|
4
|
+
def get(req, resp)
|
5
|
+
raise Exception.new("Your adaptor does not support get")
|
6
|
+
end
|
7
|
+
|
8
|
+
def put(req, resp)
|
9
|
+
raise Exception.new("Your adaptor does not support put")
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(req, resp)
|
13
|
+
raise Exception.new("Your adaptor does not support post")
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete(req, resp)
|
17
|
+
raise Exception.new("Your adaptor does not support delete")
|
18
|
+
end
|
19
|
+
|
20
|
+
def handle_call(req, resp)
|
21
|
+
update_request!
|
22
|
+
self.send req.request_method, req, resp
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(o={})
|
26
|
+
@time_til_stale = o[:time_til_stale] || Default.time_til_stale
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def parse_path(env)
|
31
|
+
env["REQUEST_URI"].gsub(/\//, '')
|
32
|
+
end
|
33
|
+
def update_request!
|
34
|
+
reload! if (Time.now.to_i - last_loaded_at >= @time_til_stale)
|
35
|
+
end
|
36
|
+
def last_loaded_at
|
37
|
+
@last_loaded_at ||= Time.now.to_i
|
38
|
+
end
|
39
|
+
def reload!
|
40
|
+
@last_loaded_at = Time.now.to_i
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
%w(yaml_file json_file).each do |lib|
|
46
|
+
require "#{File.dirname(__FILE__)}/adaptors/#{lib}_adaptor"
|
47
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Butterfly
|
4
|
+
class JsonFileAdaptor < AdaptorBase
|
5
|
+
attr_reader :data
|
6
|
+
def initialize(o={})
|
7
|
+
@file = o[:file] + ".json"
|
8
|
+
super
|
9
|
+
end
|
10
|
+
def get(req, resp)
|
11
|
+
if data.has_key?(req.params[0].to_s)
|
12
|
+
body = "", current_data = data
|
13
|
+
req.params.each do |param|
|
14
|
+
current_data = current_data[param.to_s]
|
15
|
+
end
|
16
|
+
current_data
|
17
|
+
else
|
18
|
+
resp.fail!
|
19
|
+
"Not found"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def data
|
26
|
+
@data ||= reload!
|
27
|
+
end
|
28
|
+
def reload!
|
29
|
+
super
|
30
|
+
@data = JSON.parse(open(@file).read)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Butterfly
|
4
|
+
class YamlFile < AdaptorBase
|
5
|
+
attr_reader :data
|
6
|
+
def initialize(o={})
|
7
|
+
@time_til_stale = o[:time_til_stale] || Default.time_til_stale
|
8
|
+
@file = o[:file] + ".yml"
|
9
|
+
end
|
10
|
+
def get(req, resp)
|
11
|
+
if data.has_key?(req.params[0])
|
12
|
+
body = "", current_data = data
|
13
|
+
req.params.each do |param|
|
14
|
+
current_data = current_data[param]
|
15
|
+
end
|
16
|
+
current_data
|
17
|
+
else
|
18
|
+
resp.fail!
|
19
|
+
"Not found"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def data
|
26
|
+
@data ||= reload!
|
27
|
+
end
|
28
|
+
def reload!
|
29
|
+
super
|
30
|
+
@data = YAML::load(open(@file).read)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Butterfly
|
2
|
+
class Default
|
3
|
+
include Dslify
|
4
|
+
|
5
|
+
default_options(
|
6
|
+
:host => "localhost",
|
7
|
+
:port => 8081,
|
8
|
+
:time_til_stale => 10, # 10 seconds between cache updates
|
9
|
+
:adaptor => "JsonFile",
|
10
|
+
:adaptor_opts => {
|
11
|
+
:file => "#{File.dirname(__FILE__)}/../../examples/example"
|
12
|
+
}
|
13
|
+
)
|
14
|
+
|
15
|
+
def self.method_missing(m,*a,&block)
|
16
|
+
default_options.include?(m) ? default_options[m] : super
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Butterfly
|
2
|
+
class Request
|
3
|
+
attr_reader :env
|
4
|
+
def initialize(env)
|
5
|
+
@env = env
|
6
|
+
end
|
7
|
+
def route_param
|
8
|
+
@route_param ||= params.shift
|
9
|
+
end
|
10
|
+
def params
|
11
|
+
@params ||= env["REQUEST_URI"].split("?")[0].split(".")[0].split("/").reject {|a| a.empty? }.map {|a| a.to_sym }
|
12
|
+
end
|
13
|
+
def request_method
|
14
|
+
env["REQUEST_METHOD"].downcase.to_sym
|
15
|
+
end
|
16
|
+
def request_type
|
17
|
+
env["REQUEST_URI"].split(".")[-1]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "json"
|
3
|
+
module Butterfly
|
4
|
+
class Response
|
5
|
+
attr_reader :request, :body, :status, :headers
|
6
|
+
|
7
|
+
def initialize req, b=nil
|
8
|
+
@request = req
|
9
|
+
@headers = {}
|
10
|
+
@body = b
|
11
|
+
end
|
12
|
+
def return!(b)
|
13
|
+
@body ||= b
|
14
|
+
[status, prepare_headers, prepare_body]
|
15
|
+
end
|
16
|
+
def prepare_headers
|
17
|
+
add_header("ContentType", choose_response_type)
|
18
|
+
headers
|
19
|
+
end
|
20
|
+
def prepare_body
|
21
|
+
case request.request_type
|
22
|
+
when "json"
|
23
|
+
body.to_json
|
24
|
+
else
|
25
|
+
body.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def add_header(k,v)
|
29
|
+
@headers[k] = v unless @headers.include?(k)
|
30
|
+
end
|
31
|
+
def status
|
32
|
+
@status ||= 200
|
33
|
+
end
|
34
|
+
def success!
|
35
|
+
@status = 200
|
36
|
+
end
|
37
|
+
def fail!
|
38
|
+
@status = 404
|
39
|
+
end
|
40
|
+
def choose_response_type
|
41
|
+
case request.request_type
|
42
|
+
when "json"
|
43
|
+
"application/json"
|
44
|
+
else
|
45
|
+
"text/plain"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Butterfly
|
2
|
+
class Server
|
3
|
+
attr_reader :app, :host, :port
|
4
|
+
attr_accessor :adaptor_name
|
5
|
+
def initialize(opts={})
|
6
|
+
@host = opts.delete(:host) || Default.host
|
7
|
+
@port = opts.delete(:port) || Default.port
|
8
|
+
@adaptor_opts = Default.default_options[:adaptor_opts].merge(opts)
|
9
|
+
@app = self
|
10
|
+
end
|
11
|
+
|
12
|
+
def start!
|
13
|
+
Thin::Server.start(@host, @port, app)
|
14
|
+
end
|
15
|
+
|
16
|
+
def reload!
|
17
|
+
Butterfly.reload!
|
18
|
+
end
|
19
|
+
|
20
|
+
def reloading?
|
21
|
+
@reloading == true
|
22
|
+
end
|
23
|
+
|
24
|
+
def should_reload?
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(env)
|
29
|
+
reload! if should_reload?
|
30
|
+
|
31
|
+
@request = Request.new env
|
32
|
+
@response = Response.new @request
|
33
|
+
|
34
|
+
body = get_adaptor(@request.route_param).send(:handle_call, @request, @response) rescue "Error"
|
35
|
+
|
36
|
+
@response.return!(body)
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_adaptor(p=Default.adaptor)
|
40
|
+
@adaptor ||= Butterfly.const_get("#{p.to_s.camel_case}Adaptor").new(@adaptor_opts)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/butterfly.rb'}"
|
9
|
+
puts "Loading butterfly gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestButterflyRequest < Test::Unit::TestCase
|
4
|
+
context "params" do
|
5
|
+
before do
|
6
|
+
@env = {
|
7
|
+
"REQUEST_METHOD" => "GET",
|
8
|
+
"REQUEST_URI" => "/server"
|
9
|
+
}
|
10
|
+
end
|
11
|
+
it "should parse the query into 1 part [:server] when the path is /server" do
|
12
|
+
Butterfly::Request.new(@env).params.should == [:server]
|
13
|
+
end
|
14
|
+
it "should parse the query into 2 items when the path is /server/item" do
|
15
|
+
Butterfly::Request.new(@env.merge("REQUEST_URI" => "/server/item")).params.should == [:server, :item]
|
16
|
+
end
|
17
|
+
it "should parse the query into 3 items when the path is /server/item/two" do
|
18
|
+
Butterfly::Request.new(@env.merge("REQUEST_URI" => "/server/item/two")).params.should == [:server, :item, :two]
|
19
|
+
end
|
20
|
+
it "should not explode with a ?" do
|
21
|
+
Butterfly::Request.new(@env.merge("REQUEST_URI" => "/server/item/two?pop=dance")).params.should == [:server, :item, :two]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestButterflyServer < Test::Unit::TestCase
|
4
|
+
context "server" do
|
5
|
+
before do
|
6
|
+
@server = Butterfly::Server.new({:host => "0.0.0.0", :port => 10000})
|
7
|
+
end
|
8
|
+
it "should set the host and port properly when passed in as a hash" do
|
9
|
+
@server.host.should == "0.0.0.0"
|
10
|
+
@server.port.should == 10000
|
11
|
+
end
|
12
|
+
it "should respond to call (for rack)" do
|
13
|
+
@server.respond_to?(:call).should == true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: auser-butterfly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ari Lerner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-03 00:00:00 -07:00
|
13
|
+
default_executable: flutter
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: newgem
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
version:
|
35
|
+
description: An HTTP mini server to query against modular adaptors
|
36
|
+
email:
|
37
|
+
- arilerner@mac.com
|
38
|
+
executables:
|
39
|
+
- flutter
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- History.txt
|
44
|
+
- Manifest.txt
|
45
|
+
- PostInstall.txt
|
46
|
+
- README.rdoc
|
47
|
+
files:
|
48
|
+
- History.txt
|
49
|
+
- Manifest.txt
|
50
|
+
- PostInstall.txt
|
51
|
+
- README.rdoc
|
52
|
+
- Rakefile
|
53
|
+
- bin/flutter
|
54
|
+
- butterfly.gemspec
|
55
|
+
- examples/example.json
|
56
|
+
- examples/example.yml
|
57
|
+
- lib/butterfly.rb
|
58
|
+
- lib/butterfly/adaptor_base.rb
|
59
|
+
- lib/butterfly/adaptors/json_file_adaptor.rb
|
60
|
+
- lib/butterfly/adaptors/yaml_file_adaptor.rb
|
61
|
+
- lib/butterfly/core/string.rb
|
62
|
+
- lib/butterfly/default.rb
|
63
|
+
- lib/butterfly/request.rb
|
64
|
+
- lib/butterfly/response.rb
|
65
|
+
- lib/butterfly/server.rb
|
66
|
+
- script/console
|
67
|
+
- script/destroy
|
68
|
+
- script/generate
|
69
|
+
- test/test_butterfly_request.rb
|
70
|
+
- test/test_butterfly_server.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://blog.xnot.org
|
74
|
+
post_install_message: PostInstall.txt
|
75
|
+
rdoc_options:
|
76
|
+
- --main
|
77
|
+
- README.rdoc
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
version:
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project: butterfly
|
95
|
+
rubygems_version: 1.2.0
|
96
|
+
signing_key:
|
97
|
+
specification_version: 2
|
98
|
+
summary: An HTTP mini server to query against modular adaptors
|
99
|
+
test_files:
|
100
|
+
- test/test_butterfly_request.rb
|
101
|
+
- test/test_butterfly_server.rb
|
102
|
+
- test/test_helper.rb
|