sinatra-ace 0.0.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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 2.0.1"
13
+ gem "simplecov", ">= 0"
14
+ end
15
+
16
+ gem 'sinatra'
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ diff-lcs (1.1.3)
9
+ docile (1.1.5)
10
+ faraday (0.9.0)
11
+ multipart-post (>= 1.2, < 3)
12
+ git (1.2.7)
13
+ github_api (0.11.3)
14
+ addressable (~> 2.3)
15
+ descendants_tracker (~> 0.0.1)
16
+ faraday (~> 0.8, < 0.10)
17
+ hashie (>= 1.2)
18
+ multi_json (>= 1.7.5, < 2.0)
19
+ nokogiri (~> 1.6.0)
20
+ oauth2
21
+ hashie (3.2.0)
22
+ highline (1.6.21)
23
+ jeweler (2.0.1)
24
+ builder
25
+ bundler (>= 1.0)
26
+ git (>= 1.2.5)
27
+ github_api
28
+ highline (>= 1.6.15)
29
+ nokogiri (>= 1.5.10)
30
+ rake
31
+ rdoc
32
+ json (1.8.1)
33
+ jwt (1.0.0)
34
+ mini_portile (0.6.0)
35
+ multi_json (1.10.1)
36
+ multi_xml (0.5.5)
37
+ multipart-post (2.0.0)
38
+ nokogiri (1.6.2.1)
39
+ mini_portile (= 0.6.0)
40
+ oauth2 (1.0.0)
41
+ faraday (>= 0.8, < 0.10)
42
+ jwt (~> 1.0)
43
+ multi_json (~> 1.3)
44
+ multi_xml (~> 0.5)
45
+ rack (~> 1.2)
46
+ rack (1.5.2)
47
+ rack-protection (1.5.3)
48
+ rack
49
+ rake (10.3.2)
50
+ rdoc (3.12.2)
51
+ json (~> 1.4)
52
+ rspec (2.8.0)
53
+ rspec-core (~> 2.8.0)
54
+ rspec-expectations (~> 2.8.0)
55
+ rspec-mocks (~> 2.8.0)
56
+ rspec-core (2.8.0)
57
+ rspec-expectations (2.8.0)
58
+ diff-lcs (~> 1.1.2)
59
+ rspec-mocks (2.8.0)
60
+ simplecov (0.8.2)
61
+ docile (~> 1.1.0)
62
+ multi_json
63
+ simplecov-html (~> 0.8.0)
64
+ simplecov-html (0.8.0)
65
+ sinatra (1.4.5)
66
+ rack (~> 1.4)
67
+ rack-protection (~> 1.4)
68
+ tilt (~> 1.3, >= 1.3.4)
69
+ thread_safe (0.3.4)
70
+ tilt (1.4.1)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ bundler (~> 1.0)
77
+ jeweler (~> 2.0.1)
78
+ rdoc (~> 3.12)
79
+ rspec (~> 2.8.0)
80
+ simplecov
81
+ sinatra
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 tily
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # sinatra-ace
2
+
3
+ ## Summary
4
+
5
+ Sinatra Extension for ACE (AWS Compatible Environment).
6
+
7
+ ## Features
8
+
9
+ * Friendly DSL (action, version, path)
10
+ * Specialized Helpers
11
+
12
+ ## Sample
13
+
14
+ Run this app:
15
+
16
+ require 'sinatra'
17
+ require 'sinatra/ace.rb'
18
+ require 'sequel'
19
+
20
+ DB = Sequel.sqlite
21
+ DB.create_table :dreams do
22
+ primary_key :id
23
+ String :name
24
+ String :description
25
+ end
26
+ Dreams = DB[:dreams]
27
+
28
+ action 'CreateDream' do
29
+ dream_id = Dreams.insert(:name => params['DreamName'])
30
+ response_xml do |xml|
31
+ xml.Dream do
32
+ xml.DreamId dream_id
33
+ xml.DreamName params['DreamName']
34
+ end
35
+ end
36
+ end
37
+
38
+ version '2014-07-11' do
39
+ action 'CreateDream' do
40
+ dream_id = Dreams.insert(:name => params['DreamName'], :description => params['Description'])
41
+ response_xml do |xml|
42
+ xml.Dream do
43
+ xml.DreamId dream_id
44
+ xml.DreamName params['DreamName']
45
+ xml.Description params['Description']
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ path '/:DreamId' do
52
+ action 'GetDreamDetail' do
53
+ dream = Dreams[:id => params['DreamId']]
54
+ response_xml do |xml|
55
+ xml.Dream do
56
+ xml.DreamId dream[:id]
57
+ xml.DreamName dream[:name]
58
+ xml.Description dream[:description]
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ dispatch!
65
+
66
+ And you can get:
67
+
68
+ $ curl "http://localhost:4567/?Action=CreateDream&DreamName=Nightmare"
69
+ <?xml version="1.0" encoding="UTF-8"?>
70
+ <CreateDreamResponse>
71
+ <CreateDreamResult>
72
+ <Dream>
73
+ <DreamId>2</DreamId>
74
+ <DreamName>Nightmare</DreamName>
75
+ </Dream>
76
+ </CreateDreamResult>
77
+ <ResponseMetadata>
78
+ <RequestId>6c68b49d-239a-4777-b82f-a21151e9be42</RequestId>
79
+ </ResponseMetadata>
80
+ </CreateDreamResponse>
81
+ $ curl "http://localhost:4567/?Action=CreateDream&DreamName=DayDream&Description=just+lazed+in+the+pool&Version=2014-07-11"
82
+ <?xml version="1.0" encoding="UTF-8"?>
83
+ <CreateDreamResponse>
84
+ <CreateDreamResult>
85
+ <Dream>
86
+ <DreamId>3</DreamId>
87
+ <DreamName>DayDream</DreamName>
88
+ <Description>just lazed in the pool</Description>
89
+ </Dream>
90
+ </CreateDreamResult>
91
+ <ResponseMetadata>
92
+ <RequestId>2b875603-f685-4872-a316-7e2ddd4c356d</RequestId>
93
+ </ResponseMetadata>
94
+ </CreateDreamResponse>
95
+ $ curl "http://localhost:4567/3?Action=GetDreamDetail"
96
+ <?xml version="1.0" encoding="UTF-8"?>
97
+ <GetDreamDetailResponse>
98
+ <GetDreamDetailResult>
99
+ <Dream>
100
+ <DreamId>3</DreamId>
101
+ <DreamName>DayDream</DreamName>
102
+ <Description>just lazed in the pool</Description>
103
+ </Dream>
104
+ </GetDreamDetailResult>
105
+ <ResponseMetadata>
106
+ <RequestId>225697f4-2577-432b-aa78-c6f18cec7c05</RequestId>
107
+ </ResponseMetadata>
108
+ </GetDreamDetailResponse>
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "sinatra-ace"
18
+ gem.homepage = "http://github.com/tily/sinatra-ace"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Sinatra Extension for ACE(Aws Compatible Environment)}
21
+ gem.description = %Q{Sinatra Extension for ACE(Aws Compatible Environment)}
22
+ gem.email = "tidnlyam@gmail.com"
23
+ gem.authors = ["tily"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ desc "Code coverage detail"
35
+ task :simplecov do
36
+ ENV['COVERAGE'] = "true"
37
+ Rake::Task['spec'].execute
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ #require 'rdoc/task'
43
+ #Rake::RDocTask.new do |rdoc|
44
+ # version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+ #
46
+ # rdoc.rdoc_dir = 'rdoc'
47
+ # rdoc.title = "sinatra-ace #{version}"
48
+ # rdoc.rdoc_files.include('README*')
49
+ # rdoc.rdoc_files.include('lib/**/*.rb')
50
+ #end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,106 @@
1
+ require 'sinatra/base'
2
+
3
+ module Sinatra
4
+ module Ace
5
+ module Helper
6
+ def request_id
7
+ @request_id ||= SecureRandom.uuid
8
+ end
9
+
10
+ def requested_action
11
+ params['Action']
12
+ end
13
+
14
+ def requested_version
15
+ params['Version']
16
+ end
17
+
18
+ def attributes
19
+ @attributes ||= (1..10).to_a.inject({}) do |attributes, i|
20
+ if (name = params["Attribute.#{i.to_s}.Name"]) && (value = params["Attribute.#{i.to_s}.Value"])
21
+ attributes[name] = value
22
+ end
23
+ attributes
24
+ end
25
+ end
26
+
27
+ def response_xml
28
+ builder do |xml|
29
+ xml.instruct!
30
+ xml.tag!("#{requested_action}Response") do
31
+ xml.tag!("#{requested_action}Result") do
32
+ yield(xml)
33
+ end
34
+ xml.ResponseMetadata { xml.RequestId request_id }
35
+ end
36
+ end
37
+ end
38
+
39
+ def error_xml(type, code, message)
40
+ builder do |xml|
41
+ xml.instruct!
42
+ xml.ErrorResponse do
43
+ xml.Error do
44
+ xml.Type type
45
+ xml.Code code
46
+ xml.Message message
47
+ end
48
+ xml.ResponseMetadata { xml.RequestId request_id }
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+
55
+ module Dsl
56
+ attr_reader :actions
57
+
58
+ def action(action, options={}, &block)
59
+ @actions ||= Array.new
60
+ raise 'Error: path was specified at two places' if options[:path] && @path
61
+ raise 'Error: version was specified at two places' if options[:version] && @version
62
+ path = @path || options[:path] || '/'
63
+ version = @version || options[:version] || nil
64
+ @actions << {action: action, block: block, path: path, version: version}
65
+ end
66
+
67
+ def version(version)
68
+ original_version = @version
69
+ @version = version
70
+ yield
71
+ @version = original_version
72
+ end
73
+
74
+ def path(path)
75
+ original_path = @path
76
+ @path = path
77
+ yield
78
+ @path = original_path
79
+ end
80
+
81
+ def dispatch!
82
+ paths = @actions.map {|action| action[:path] }.uniq
83
+ paths.each do |path|
84
+ [:get, :post].each do |x|
85
+ send(x, path) do
86
+ actions = self.class.actions.select do |action|
87
+ action[:path] == env['sinatra.route'].split(' ').last &&
88
+ action[:action] == requested_action &&
89
+ [requested_version, nil].include?(action[:version])
90
+ end
91
+ raise 'Error: action was not found' if actions.empty? # TODO: raise custom error
92
+ action = actions.find {|action| action[:version] == requested_version } || actions.first
93
+ logger.info "calling action: #{action}"
94
+ instance_eval(&action[:block])
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ end
102
+ end
103
+
104
+ # register for classic style
105
+ Sinatra.register Sinatra::Ace::Dsl
106
+ Sinatra.helpers Sinatra::Ace::Helper
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SinatraAce" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'rspec'
21
+ require 'sinatra/ace'
22
+
23
+ # Requires supporting files with custom matchers and macros, etc,
24
+ # in ./support/ and its subdirectories.
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
26
+
27
+ RSpec.configure do |config|
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-ace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tily
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.8.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.8.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.0.1
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.0.1
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Sinatra Extension for ACE(Aws Compatible Environment)
111
+ email: tidnlyam@gmail.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files:
115
+ - LICENSE.txt
116
+ - README.md
117
+ files:
118
+ - .document
119
+ - .rspec
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - VERSION
126
+ - lib/sinatra/ace.rb
127
+ - spec/sinatra-ace_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: http://github.com/tily/sinatra-ace
130
+ licenses:
131
+ - MIT
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ segments:
143
+ - 0
144
+ hash: 1272371909116950658
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 1.8.23
154
+ signing_key:
155
+ specification_version: 3
156
+ summary: Sinatra Extension for ACE(Aws Compatible Environment)
157
+ test_files: []