airship 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d5752dd33f6ee29b3f794c319321e2e828bf6f9
4
+ data.tar.gz: 7e91e4269300fc32ed527c75230726d75abe79e4
5
+ SHA512:
6
+ metadata.gz: ba9cc55bf2fe8c87972c3f0d15e1ad073782bda7c25696bb6ea985e90479ee7886599d4b09478c594550494615a4cddb7cda731c05b3423d66c3f846ebcaff17
7
+ data.tar.gz: 513d4f546cc32dbfffd597531f340046a96fe1854bedab6e324a8745d1a3f2f8fc4703858ca80b3a5ad2b4bbcda6a126a143bea6f1405368e0482cdbc2972b7f
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,20 @@
1
+ lang: ruby
2
+ before_install: gem install bundler --pre
3
+ install:
4
+ - gem update --system
5
+ - bundle update
6
+ rvm:
7
+ - 2.0.0
8
+ - 2.1.0
9
+ - jruby-head
10
+ - rbx
11
+ notifications:
12
+ recipients:
13
+ - namusyaka@gmail.com
14
+ branches:
15
+ only:
16
+ - master
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: rbx
20
+ - rvm: jruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in airship.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 namusyaka
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,164 @@
1
+ # Airship
2
+
3
+ Airship is the Sinatra/Padrino extension.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'airship'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install airship
18
+
19
+ ## Usage
20
+
21
+ ### Attachment
22
+
23
+ Airship::Attachment enables to use :to option with verbs and filters
24
+
25
+ #### with Sinatra
26
+
27
+ ```ruby
28
+ class Sample::App < Sinatra::Base
29
+ register Airship::Attachment::Sinatra
30
+
31
+ def before_index
32
+ @hello = :Hello
33
+ end
34
+
35
+ def index
36
+ "#{@hello} World"
37
+ end
38
+
39
+ def show(name, type)
40
+ "#{name} is #{type}"
41
+ end
42
+
43
+ before "/", to: :before_index
44
+
45
+ get "/", to: :index
46
+ get "/show/:name/:type", to: :show
47
+
48
+ end
49
+ ```
50
+
51
+ #### with Padrino
52
+
53
+ ```ruby
54
+ class Sample::App < Padrino::Application
55
+ register Airship::Attachment::Padrino
56
+
57
+ def before_index
58
+ @hello = :Hello
59
+ end
60
+
61
+ def index
62
+ "#{@hello} World"
63
+ end
64
+
65
+ def show(name, type)
66
+ "#{name} is #{type}"
67
+ end
68
+
69
+ before :index, to: :before_index
70
+ get :index, to: :index
71
+ get :show, map: "/show/:name/:type", to: :show
72
+
73
+ end
74
+ ```
75
+
76
+ ### Management
77
+
78
+ Airship::Management provides yet another DSL built upon the Sinatra/Padrino library.
79
+
80
+ #### with Sinatra
81
+
82
+ ```ruby
83
+ class Sample::App < Sinatra::Base
84
+ register Airship::Management::Sinatra
85
+
86
+ index do
87
+ "GET /"
88
+ end
89
+
90
+ show do
91
+ "GET /:id"
92
+ end
93
+
94
+ edit do
95
+ "GET /:id/edit"
96
+ end
97
+
98
+ update do
99
+ "POST /:id/update"
100
+ end
101
+
102
+ destroy do
103
+ "DELETE /:id/delete"
104
+ end
105
+ end
106
+ ```
107
+
108
+ #### with Padrino
109
+
110
+ ```ruby
111
+ class Sample::App < Padrino::Application
112
+ register Airship::Management::Padrino
113
+
114
+ index do
115
+ "GET /"
116
+ end
117
+
118
+ show do
119
+ "GET /:id"
120
+ end
121
+
122
+ edit do
123
+ "GET /:id/edit"
124
+ end
125
+
126
+ update do
127
+ "POST /:id/update"
128
+ end
129
+
130
+ destroy do
131
+ "DELETE /:id/delete"
132
+ end
133
+
134
+ controller :resources do
135
+ index do
136
+ "GET /resources"
137
+ end
138
+
139
+ show do
140
+ "GET /resources/:id"
141
+ end
142
+
143
+ edit do
144
+ "GET /resources/:id/edit"
145
+ end
146
+
147
+ update do
148
+ "POST /resources/:id/update"
149
+ end
150
+
151
+ destroy do
152
+ "DELETE /resources/:id/delete"
153
+ end
154
+ end
155
+ end
156
+ ```
157
+
158
+ ## Contributing
159
+
160
+ 1. Fork it ( https://github.com/namusyaka/airship/fork )
161
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
162
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
163
+ 4. Push to the branch (`git push origin my-new-feature`)
164
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << "test"
6
+ test.test_files = Dir['test/*_test.rb']
7
+ test.verbose = true
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'airship/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "airship"
8
+ spec.version = Airship::VERSION
9
+ spec.authors = ["namusyaka"]
10
+ spec.email = ["namusyaka@gmail.com"]
11
+ spec.summary = %q{Airship is the Sinatra/Padrino extension.}
12
+ spec.description = spec.description
13
+ spec.homepage = "http://github.com/namusyaka/airship"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rack-test"
24
+ spec.add_development_dependency "minitest"
25
+ spec.add_development_dependency "padrino"
26
+ spec.add_development_dependency "sinatra"
27
+ end
@@ -0,0 +1,6 @@
1
+ require "airship/version"
2
+
3
+ module Airship
4
+ autoload :Attachment, "airship/attachment"
5
+ autoload :Management, "airship/management"
6
+ end
@@ -0,0 +1,46 @@
1
+
2
+ module Airship
3
+ module Attachment
4
+ ##
5
+ # Airship::Attachment enables to use :to option with verb methods
6
+ #
7
+ # @example Sinatra
8
+ #
9
+ # class Sample < Sinatra::Base
10
+ # register Airship::Attachment::Sinatra
11
+ #
12
+ # def hello
13
+ # "Hello World"
14
+ # end
15
+ #
16
+ # def show(id)
17
+ # "This is #{id}"
18
+ # end
19
+ #
20
+ # get "/", to: :hello
21
+ # get "/:id", to: :show
22
+ # end
23
+ #
24
+ # @example Padrino
25
+ #
26
+ # class Sample < Padrino::Application
27
+ # register Airship::Attachment::Padrino
28
+ #
29
+ # def hello
30
+ # "Hello World"
31
+ # end
32
+ #
33
+ # def show(id)
34
+ # "This is #{id}"
35
+ # end
36
+ #
37
+ # get :index, to: :hello
38
+ # get :show, with: :id, to: :show
39
+ # end
40
+ #
41
+ UndefinedMethod = Class.new(ArgumentError)
42
+
43
+ autoload :Sinatra, "airship/attachment/sinatra"
44
+ autoload :Padrino, "airship/attachment/padrino"
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ require_relative '../extensions/padrino'
2
+
3
+ module Airship
4
+ module Attachment
5
+ module Padrino
6
+
7
+ def self.registered(app)
8
+ app.extend ClassMethods
9
+ end
10
+
11
+ module ClassMethods
12
+ include Airship::Extensions::Padrino
13
+
14
+ def construct_filter(*args, &block)
15
+ options = args.last.is_a?(Hash) ? args.pop : {}
16
+ name = options.delete(:to)
17
+
18
+ if name.instance_of?(Symbol) && !block_given?
19
+ unbound_method = instance_method(name) rescue undefined_method(name)
20
+ block = proc{ unbound_method.bind(self).call }
21
+ end
22
+
23
+ except = options.key?(:except) && Array(options.delete(:except))
24
+ raise("You cannot use except with other options specified") if except && (!args.empty? || !options.empty?)
25
+ options = except.last.is_a?(Hash) ? except.pop : {} if except
26
+ ::Padrino::Filter.new(!except, @_controller, options, Array(except || args), &block)
27
+ end
28
+
29
+ def generate_unbound_method(verb, path, options, &block)
30
+ name = options.delete(:to)
31
+ if name.instance_of?(Symbol) && !block_given?
32
+ instance_method(name) rescue undefined_method(name)
33
+ else
34
+ super
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def undefined_method(name)
41
+ raise UndefinedMethod, "undefined method `#{name}`."
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,41 @@
1
+
2
+ module Airship
3
+ module Attachment
4
+ module Sinatra
5
+
6
+ def self.registered(app)
7
+ app.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def compile!(verb, path, block, options = {})
12
+ options = options.dup
13
+
14
+ if method_name = options.delete(:to)
15
+ block = unbound_method = instance_method(method_name) rescue undefined_method(method_name)
16
+ else
17
+ method_name = "#{verb} #{path}"
18
+ unbound_method = generate_method(method_name, &block)
19
+ end
20
+
21
+ options.each_pair { |option, args| send(option, *args) }
22
+ pattern, keys = compile path
23
+ conditions, @conditions = @conditions, []
24
+
25
+ wrapper = block.arity != 0 ?
26
+ proc { |a,p| unbound_method.bind(a).call(*p) } :
27
+ proc { |a,p| unbound_method.bind(a).call }
28
+ wrapper.instance_variable_set(:@route_name, method_name)
29
+
30
+ [ pattern, keys, conditions, wrapper ]
31
+ end
32
+
33
+ private
34
+
35
+ def undefined_method(name)
36
+ raise UndefinedMethod, "undefined method `#{name}`."
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,112 @@
1
+ module Airship
2
+ module Extensions
3
+ module Padrino
4
+ ##
5
+ # Airship::Extensions::Padrino separates methods of Padrino::Routing to convenient size.
6
+
7
+ ROUTE_PRIORITY = {:high => 0, :normal => 1, :low => 2} unless defined?(ROUTE_PRIORITY)
8
+
9
+ def route(verb, path, *args, &block)
10
+ options = extract_options(args)
11
+ route_options = build_route_options(options)
12
+ path, *route_options[:with] = path if path.is_a?(Array)
13
+ action = path
14
+ path, name, route_parents, options, route_options = *parse_route(path, route_options, verb)
15
+ options.reverse_merge!(@_conditions) if @_conditions
16
+ block = generate_block(verb, path, options, block)
17
+ options.merge!(name: name, route_options: route_options, parents: route_parents, action: action)
18
+ register_route(verb, path, args, options, &block)
19
+ end
20
+
21
+ private
22
+
23
+ def register_route(verb, path, args, options, &block)
24
+ route = router.add(path, options.delete(:route_options))
25
+ route.action = options.delete(:action)
26
+ route.add_request_method(verb.downcase.to_sym)
27
+ invoke_hook(:route_added, verb, path, block)
28
+
29
+ priority_name = options.delete(:priority) || :normal
30
+ priority = ROUTE_PRIORITY[priority_name] or raise("Priority #{priority_name} not recognized, try #{ROUTE_PRIORITY.keys.join(', ')}")
31
+ deferred_routes[priority] << [set_parameters(route, options), block]
32
+
33
+ # for page caching
34
+ invoke_hook(:padrino_route_added, route, verb, path, args, options, block)
35
+ end
36
+
37
+ def set_parameters(route, options)
38
+ route.name = options.delete(:name)
39
+ route.cache = options.key?(:cache) ? options.delete(:cache) : @_cache if options.key?(:cache)
40
+ route.user_agent = options.delete(:agent) if options.key?(:agent)
41
+ route.host = options.delete(:host) if options.key?(:host)
42
+
43
+ if @_controller
44
+ route.use_layout = @layout
45
+ route.controller = Array(@_controller).join('/')
46
+ end
47
+
48
+ parents = options.delete(:parents)
49
+ route.parent = parents ? (parents.count == 1 ? parents.first : parents) : parents
50
+
51
+ if options.key?(:default_values)
52
+ defaults = options.delete(:default_values)
53
+ route.add_default_values(defaults) if defaults
54
+ end
55
+
56
+ options.delete_if do |option, args|
57
+ if route.significant_variable_names.include?(option)
58
+ route.add_match_with(option => Array(args).first)
59
+ true
60
+ end
61
+ end
62
+
63
+ options.each{|o, a| route.respond_to?(o) ? route.send(o, *a) : send(o, *a) }
64
+ conditions, @conditions = @conditions, []
65
+ route.custom_conditions.concat(conditions)
66
+ route.before_filters << @filters[:before]
67
+ route.after_filters << @filters[:after]
68
+ route
69
+ end
70
+
71
+ def generate_unbound_method(verb, path, options, &block)
72
+ method_name = "#{verb} #{path}"
73
+ generate_method(method_name, &block)
74
+ end
75
+
76
+ def generate_block(verb, path, options, block)
77
+ unbound_method = generate_unbound_method(verb, path, options, &block)
78
+ unbound_method.arity != 0 ?
79
+ proc{|a, p| unbound_method.bind(a).call(*p) } :
80
+ proc{|a, p| unbound_method.bind(a).call }
81
+ end
82
+
83
+
84
+ def build_route_options(options)
85
+ route_options = options.dup
86
+ [:provides, :accepts].each{|name|
87
+ (var = instance_variable_get(:"@_#{name}")) && (route_options[name] = var) }
88
+ unless route_options.has_key?(:csrf_protection)
89
+ route_options[:csrf_protection] = true
90
+ end if protect_from_csrf && (report_csrf_failure || allow_disabled_csrf)
91
+ route_options
92
+ end
93
+
94
+ def extract_options(args)
95
+ case args.size
96
+ when 2
97
+ args.last.merge(map: args.first)
98
+ when 1
99
+ map = args.shift if args.first.is_a?(String)
100
+ if args.first.is_a?(Hash)
101
+ map ? args.first.merge(map: map) : args.first
102
+ else
103
+ { map: map || args.first }
104
+ end
105
+ when 0
106
+ {}
107
+ else raise
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,65 @@
1
+
2
+ module Airship
3
+ module Management
4
+ ##
5
+ # Airship::Management provides some useful methods for use in an environment like CRUD
6
+ #
7
+ # @example Sinatra
8
+ #
9
+ # class Sample < Sinatra::Base
10
+ # register Airship::Management::Sinatra
11
+ #
12
+ # index do
13
+ # "GET /"
14
+ # end
15
+ #
16
+ # show do
17
+ # "GET /:id"
18
+ # end
19
+ #
20
+ # edit do
21
+ # "GET /edit/:id"
22
+ # end
23
+ #
24
+ # update do
25
+ # "POST /update/:id"
26
+ # end
27
+ #
28
+ # destroy do
29
+ # "POST /destroy/:id"
30
+ # end
31
+ # end
32
+ #
33
+ # @example Padrino
34
+ #
35
+ # class Sample < Padrino::Application
36
+ # register Airship::Attachment::Padrino
37
+ #
38
+ # controller :article do
39
+ # index do
40
+ # "GET /article"
41
+ # end
42
+ #
43
+ # show do
44
+ # "GET /article/:id"
45
+ # end
46
+ #
47
+ # edit do
48
+ # "GET /article/edit/:id"
49
+ # end
50
+ #
51
+ # update provides: [:xml, :json] do
52
+ # "PUT /article/update/:id.(:format)"
53
+ # end
54
+ #
55
+ # destroy provides: [:xml, :json] do
56
+ # "DELETE /article/destroy/:id.(:format)"
57
+ # end
58
+ # end
59
+ # end
60
+ #
61
+
62
+ autoload :Sinatra, "airship/management/sinatra"
63
+ autoload :Padrino, "airship/management/padrino"
64
+ end
65
+ end
@@ -0,0 +1,31 @@
1
+ module Airship
2
+ module Management
3
+ module Padrino
4
+ def self.registered(app)
5
+ app.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def index(options = {}, &block)
10
+ route 'GET', "", options, &block
11
+ end
12
+
13
+ def show(options = {}, &block)
14
+ route 'GET', ":id", options, &block
15
+ end
16
+
17
+ def edit(options = {}, &block)
18
+ route 'GET', ":id/edit", options, &block
19
+ end
20
+
21
+ def update(options = {}, &block)
22
+ route 'POST', ":id/update", options, &block
23
+ end
24
+
25
+ def destroy(options = {}, &block)
26
+ route 'DELETE', ":id/destroy", options, &block
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module Airship
2
+ module Management
3
+ module Sinatra
4
+ def self.registered(app)
5
+ app.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def index(options = {}, &block)
10
+ get "/", options, &block
11
+ end
12
+
13
+ def show(options = {}, &block)
14
+ get "/:id", options, &block
15
+ end
16
+
17
+ def edit(options = {}, &block)
18
+ get "/:id/edit", options, &block
19
+ end
20
+
21
+ def update(options = {}, &block)
22
+ post "/:id/update", options, &block
23
+ end
24
+
25
+ def destroy(options = {}, &block)
26
+ delete "/:id/destroy", options, &block
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Airship
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,146 @@
1
+ require File.expand_path('../../lib/airship/attachment', __FILE__)
2
+ $:.unshift(File.dirname(__FILE__))
3
+ require 'helper'
4
+
5
+ describe Airship::Attachment do
6
+ context Sinatra do
7
+ describe :to do
8
+ before do
9
+ mock_app Sinatra::Base do
10
+ register Airship::Attachment::Sinatra
11
+
12
+ def hello
13
+ "Hello World"
14
+ end
15
+
16
+ def show(id, type)
17
+ "id: #{id}, type: #{type}"
18
+ end
19
+
20
+ def hey
21
+ @a
22
+ end
23
+
24
+ def bar
25
+ @b = "bar"
26
+ end
27
+
28
+ def show_bar
29
+ @b
30
+ end
31
+
32
+ get "/", to: :hello
33
+ get "/show/:id/:type", to: :show
34
+
35
+ before("/foo"){ @a = "hey" }
36
+ get "/foo", to: :hey
37
+
38
+ before "/bar", to: :bar
39
+ get "/bar", to: :show_bar
40
+ end
41
+ end
42
+
43
+ it "can be attached to instance method" do
44
+ get '/'
45
+ assert_equal 'Hello World', last_response.body
46
+ end
47
+
48
+ it "can take the captures" do
49
+ get '/show/1234/frank'
50
+ assert_equal 'id: 1234, type: frank', last_response.body
51
+ end
52
+
53
+ it "can treat the instance variable" do
54
+ get '/foo'
55
+ assert_equal 'hey', last_response.body
56
+ end
57
+
58
+ it "can be attached to instance method with the filters" do
59
+ get '/bar'
60
+ assert_equal 'bar', last_response.body
61
+ end
62
+
63
+ it "occurs UndefinedMethod error if method is undefined" do
64
+ assert_raises Airship::Attachment::UndefinedMethod do
65
+ mock_app(Sinatra::Base) do
66
+ register Airship::Attachment::Sinatra
67
+ get "/dummy", to: :undefined
68
+ end
69
+ end
70
+ assert_raises Airship::Attachment::UndefinedMethod do
71
+ mock_app(Sinatra::Base) do
72
+ register Airship::Attachment::Sinatra
73
+ before "/dummy", to: :undefined
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ context Padrino do
81
+ describe :to do
82
+ before do
83
+ Padrino::Application.send(:register, Airship::Attachment::Padrino)
84
+ mock_app do
85
+ def hello
86
+ "Hello World"
87
+ end
88
+
89
+ def show(id, type)
90
+ "id: #{id}, type: #{type}"
91
+ end
92
+
93
+ def hey
94
+ @a
95
+ end
96
+
97
+ def bar
98
+ @b = "bar"
99
+ end
100
+
101
+ def show_bar
102
+ @b
103
+ end
104
+
105
+ get :index, to: :hello
106
+ get :show, "/show/:id/:type", to: :show
107
+
108
+ before(:foo){ @a = "hey" }
109
+ get :foo, to: :hey
110
+
111
+ before :bar, to: :bar
112
+ get :bar, to: :show_bar
113
+ end
114
+ end
115
+
116
+ it "can be attached to instance method" do
117
+ get '/'
118
+ assert_equal 'Hello World', last_response.body
119
+ end
120
+
121
+ it "can take the captures" do
122
+ get '/show/1234/frank'
123
+ assert_equal 'id: 1234, type: frank', last_response.body
124
+ end
125
+
126
+ it "can treat the instance variable" do
127
+ get '/foo'
128
+ assert_equal 'hey', last_response.body
129
+ end
130
+
131
+ it "can be attached to instance method with the filters" do
132
+ get '/bar'
133
+ assert_equal 'bar', last_response.body
134
+ end
135
+
136
+ it "occurs UndefinedMethod error if method is undefined" do
137
+ assert_raises Airship::Attachment::UndefinedMethod do
138
+ mock_app{ get :dummy, to: :undefined }
139
+ end
140
+ assert_raises Airship::Attachment::UndefinedMethod do
141
+ mock_app{ before :dummy, to: :undefined }
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,26 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+ require 'rack/test'
4
+ require 'sinatra/base'
5
+ require 'padrino-core'
6
+
7
+ class Sinatra::Base
8
+ include MiniTest::Assertions
9
+ end
10
+
11
+ class MiniTest::Spec
12
+ include Rack::Test::Methods
13
+
14
+ class << self
15
+ alias context describe
16
+ end
17
+
18
+ def app
19
+ Rack::Lint.new(@app)
20
+ end
21
+
22
+ def mock_app(base = Padrino::Application, &block)
23
+ @app = Sinatra.new(base, &block)
24
+ @app.set :logging, false
25
+ end
26
+ end
@@ -0,0 +1,89 @@
1
+ require File.expand_path('../../lib/airship/management', __FILE__)
2
+ $:.unshift(File.dirname(__FILE__))
3
+ require 'helper'
4
+
5
+ describe Airship::Management do
6
+ context Sinatra do
7
+ describe :routing do
8
+ before do
9
+ mock_app Sinatra::Base do
10
+ register Airship::Management::Sinatra
11
+
12
+ index { "index!" }
13
+ show { "show #{params[:id]}" }
14
+ edit { "edit #{params[:id]}" }
15
+ update { "update #{params[:id]}" }
16
+ destroy { "destroy #{params[:id]}" }
17
+
18
+ get("/hey/ho"){ "Hey" }
19
+ end
20
+ end
21
+
22
+ it "can be used to define the regular routes" do
23
+ get "/"
24
+ assert_equal "index!", last_response.body
25
+ get "/1234"
26
+ assert_equal "show 1234", last_response.body
27
+ get "/5678/edit"
28
+ assert_equal "edit 5678", last_response.body
29
+ post "/5678/update"
30
+ assert_equal "update 5678", last_response.body
31
+ delete "/5678/destroy"
32
+ assert_equal "destroy 5678", last_response.body
33
+ end
34
+
35
+ it "should not break the compatibility with sinatra" do
36
+ get "/hey/ho"
37
+ assert_equal "Hey", last_response.body
38
+ end
39
+ end
40
+ end
41
+
42
+ context Padrino do
43
+ describe :routing do
44
+ before do
45
+ mock_app do
46
+ register Airship::Management::Padrino
47
+
48
+ index { "index!" }
49
+ show { "show #{params[:id]}" }
50
+ edit { "edit #{params[:id]}" }
51
+ update { "update #{params[:id]}" }
52
+ destroy { "destroy #{params[:id]}" }
53
+
54
+ get(:heyho, map: "/hey/ho"){ "Hey" }
55
+
56
+ controller :resources do
57
+ show { "resource show #{params[:id]}" }
58
+ edit { "resource edit #{params[:id]}" }
59
+ end
60
+ end
61
+ end
62
+
63
+ it "can be used to define the regular routes" do
64
+ get "/"
65
+ assert_equal "index!", last_response.body
66
+ get "/1234"
67
+ assert_equal "show 1234", last_response.body
68
+ get "/5678/edit"
69
+ assert_equal "edit 5678", last_response.body
70
+ post "/5678/update"
71
+ assert_equal "update 5678", last_response.body
72
+ delete "/5678/destroy"
73
+ assert_equal "destroy 5678", last_response.body
74
+ end
75
+
76
+ it "should not break the compatibility with padrino" do
77
+ get "/hey/ho"
78
+ assert_equal "Hey", last_response.body
79
+ end
80
+
81
+ it "should be able to use it on the controller" do
82
+ get "/resources/1234"
83
+ assert_equal "resource show 1234", last_response.body
84
+ get "/resources/1234/edit"
85
+ assert_equal "resource edit 1234", last_response.body
86
+ end
87
+ end
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: airship
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - namusyaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: padrino
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sinatra
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ''
98
+ email:
99
+ - namusyaka@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - airship.gemspec
111
+ - lib/airship.rb
112
+ - lib/airship/attachment.rb
113
+ - lib/airship/attachment/padrino.rb
114
+ - lib/airship/attachment/sinatra.rb
115
+ - lib/airship/extensions/padrino.rb
116
+ - lib/airship/management.rb
117
+ - lib/airship/management/padrino.rb
118
+ - lib/airship/management/sinatra.rb
119
+ - lib/airship/version.rb
120
+ - test/attachment_test.rb
121
+ - test/helper.rb
122
+ - test/management_test.rb
123
+ homepage: http://github.com/namusyaka/airship
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.0.14
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Airship is the Sinatra/Padrino extension.
147
+ test_files:
148
+ - test/attachment_test.rb
149
+ - test/helper.rb
150
+ - test/management_test.rb
151
+ has_rdoc: