rack_session_manipulation 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70ee014ab99f99fa2f2ad204ce13a2bd7962a7ad
4
+ data.tar.gz: ef49f9684ecaf820f6f8d0d0786d4c2aa0192f7c
5
+ SHA512:
6
+ metadata.gz: 069c8f5fe4346c9abf868ef3ba77c770fe34b6cd067e80f281fe8cac52a432de106119ac252fb47de0184a4792a9ed824d2b6ab340ed2da2aeeadf1715263aaf
7
+ data.tar.gz: aa3860206e132799bad764c79cd029f4f1af5ef4403bccf0c9d3762cba2be65630025f5d8cdce8302d490252d6663f1662bab9bf0ab4905f0b0d639a2b6cb51d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ RSpec/FilePath:
2
+ Enabled: false
3
+ require:
4
+ - rubocop-rspec
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.1.5
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --default-return void --private --protected
@@ -0,0 +1,27 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all
4
+ people who contribute through reporting issues, posting feature requests,
5
+ updating documentation, submitting pull requests or patches, and other
6
+ activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, age, or religion.
12
+
13
+ Examples of unacceptable behavior by participants include the use of sexual
14
+ language or imagery, derogatory comments or personal attacks, trolling, public
15
+ or private harassment, insults, or other unprofessional conduct.
16
+
17
+ Project maintainers have the right and responsibility to remove, edit, or
18
+ reject comments, commits, code, wiki edits, issues, and other contributions
19
+ that are not aligned to this Code of Conduct. Project maintainers who do not
20
+ follow the Code of Conduct may be removed from the project team.
21
+
22
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
23
+ reported by opening an issue or contacting one or more of the project
24
+ maintainers.
25
+
26
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at
27
+ [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Sam Stelfox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # RackSessionManipulation
2
+
3
+ [![Build Status](https://travis-ci.org/sstelfox/rack_session_manipulation.svg)](https://travis-ci.org/sstelfox/rack_session_manipulation)
4
+ [![Coverage Status](https://coveralls.io/repos/sstelfox/rack_session_manipulation/badge.svg?branch=develop)](https://coveralls.io/r/sstelfox/rack_session_manipulation?branch=develop)
5
+ [![Dependency Status](https://gemnasium.com/sstelfox/rack_session_manipulation.svg)](https://gemnasium.com/sstelfox/rack_session_manipulation)
6
+ [![Code Climate](https://codeclimate.com/github/sstelfox/rack_session_manipulation/badges/gpa.svg)](https://codeclimate.com/github/sstelfox/rack_session_manipulation)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'rack_session_manipulation'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install rack_session_manipulation
23
+
24
+ ## Usage
25
+
26
+ ## Contributing
27
+
28
+ 1. Reivew the [Contributor Code of Conduct](CODE_OF_CONDUCT.md)
29
+ 2. Fork it ( https://github.com/sstelfox/rack_session_manipulation/fork )
30
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 5. Push to the branch (`git push origin my-new-feature`)
33
+ 6. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ puts 'RSpec isn\'t available to the rake environment'
8
+ end
9
+
10
+ begin
11
+ require 'rubocop/rake_task'
12
+ RuboCop::RakeTask.new(:rubocop) do |task|
13
+ task.formatters = %w(simple offenses)
14
+ task.fail_on_error = false
15
+ task.options = %w(--format html --out doc/rubocop.html)
16
+ end
17
+ rescue LoadError
18
+ puts 'Rubocop isn\'t available to the rake environment'
19
+ end
20
+
21
+ begin
22
+ require 'yard'
23
+ YARD::Rake::YardocTask.new(:docs)
24
+ rescue LoadError
25
+ puts 'Yardoc isn\'t available to the rake environment'
26
+ end
27
+
28
+ task :default do
29
+ Rake::Task[:docs].invoke if Rake::Task.task_defined?(:docs)
30
+ Rake::Task[:rubocop].invoke if Rake::Task.task_defined?(:rubocop)
31
+ Rake::Task[:spec].invoke if Rake::Task.task_defined?(:spec)
32
+ end
33
+
34
+ task 'environment' do
35
+ require 'rack_session_manipulation'
36
+ end
37
+
38
+ desc 'Run a console with the application loaded'
39
+ task console: [:environment] do
40
+ require 'pry'
41
+ pry
42
+ end
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+
3
+ require 'rack_session_manipulation/config'
4
+ require 'rack_session_manipulation/middleware'
5
+ require 'rack_session_manipulation/utilities'
6
+ require 'rack_session_manipulation/version'
7
+
8
+ # Parent module for the Rack Session Manipulation middleware.
9
+ module RackSessionManipulation
10
+ extend RackSessionManipulation::Utilities
11
+
12
+ def self.config
13
+ @config ||= RackSessionManipulation::Config.new(random_path_prefix)
14
+ end
15
+
16
+ def self.configure
17
+ yield(config)
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ # Parent module for the Rack Session Manipulation middleware.
2
+ module RackSessionManipulation
3
+ # Capybara helpers for accessing and setting session values
4
+ module Capybara
5
+ def session=(hash)
6
+ data = { 'session_data' => RackSessionManipulation.encode(hash) }
7
+ driver.put(RackSessionManipulation.config.path, data)
8
+ end
9
+
10
+ def session
11
+ driver.get(RackSessionManipulation.config.path)
12
+ RackSessionManipulation.decode(driver.response.body)
13
+ end
14
+ end
15
+ end
16
+
17
+ require 'capybara/session'
18
+ Capybara::Session.send(:include, RackSessionManipulation::Capybara)
@@ -0,0 +1,4 @@
1
+ # Parent module for the Rack Session Manipulation middleware.
2
+ module RackSessionManipulation
3
+ Config = Struct.new(:path)
4
+ end
@@ -0,0 +1,59 @@
1
+ # Parent module for the Rack Session Manipulation middleware.
2
+ module RackSessionManipulation
3
+ # Rack middleware that handles the accessing and modification of session
4
+ # state.
5
+ class Middleware
6
+ def call(env)
7
+ request = Rack::Request.new(env)
8
+
9
+ action = get_action(request)
10
+ action.nil? ? @app.call(env) : send(action, request)
11
+ end
12
+
13
+ def initialize(app, _options = {})
14
+ @app = app
15
+ @routes = {
16
+ 'GET' => :retrieve,
17
+ 'PUT' => :update
18
+ }
19
+ end
20
+
21
+ protected
22
+
23
+ def extract_method(request)
24
+ return request.request_method unless request.request_method == 'POST'
25
+ return request.params['_method'].upcase if request.params['_method']
26
+ request.request_method
27
+ end
28
+
29
+ def get_action(request)
30
+ return unless request.path == RackSessionManipulation.config.path
31
+ @routes[extract_method(request)]
32
+ end
33
+
34
+ def headers(length)
35
+ {
36
+ 'Content-Type' => 'application/json',
37
+ 'Content-Length' => length
38
+ }
39
+ end
40
+
41
+ def retrieve(request)
42
+ session_hash = request.env['rack.session'].to_hash
43
+ content = RackSessionManipulation.encode(session_hash)
44
+
45
+ [200, headers(content.length), content]
46
+ end
47
+
48
+ def update(request)
49
+ session_data = request.params['session_data']
50
+ RackSessionManipulation.decode(session_data).each do |k, v|
51
+ request.env['rack.session'][k] = v
52
+ end
53
+
54
+ [204, headers(0), '']
55
+ rescue JSON::ParserError
56
+ [400, headers(0), '']
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,29 @@
1
+ # Parent module for the Rack Session Manipulation middleware.
2
+ module RackSessionManipulation
3
+ # Various utility methods that will be module level functions for the parent
4
+ # namespace module.
5
+ module Utilities
6
+ def decode(encoded_data)
7
+ JSON.parse(encoded_data)
8
+ end
9
+
10
+ def encode(obj)
11
+ JSON.generate(obj)
12
+ end
13
+
14
+ # SecureRandom raises a NotImplementedError if no random device is
15
+ # available in that case fallback on Kernel.rand. Shamelessly stolen from
16
+ # the Sinatra session secret generation code.
17
+ #
18
+ # @return [String]
19
+ def random_path_prefix
20
+ num = begin
21
+ require 'securerandom'
22
+ SecureRandom.random_number(2**64 - 1)
23
+ rescue LoadError, NotImplementedError
24
+ Kernel.rand(2**64 - 1)
25
+ end
26
+ format('/%016x', num)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ # Parent module for the Rack Session Manipulation middleware.
2
+ module RackSessionManipulation
3
+ # The current version of this module
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'rack_session_manipulation/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rack_session_manipulation'
9
+ spec.version = RackSessionManipulation::VERSION
10
+ spec.authors = ['Sam Stelfox']
11
+ spec.email = ['sstelfox@bedroomprogrammers.net']
12
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f =~ /^spec\// }
13
+
14
+ spec.summary = 'A rack middleware for exposing session state to tests.'
15
+ spec.description = 'A rack middleware for exposing session state to tests.'
16
+ spec.homepage = 'https://github.com/sstelfox/rack_session_manipulation'
17
+ spec.license = 'MIT'
18
+
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'pry'
23
+ spec.add_development_dependency 'rake'
24
+
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'capybara'
27
+
28
+ spec.add_development_dependency 'coveralls'
29
+ spec.add_development_dependency 'simplecov'
30
+
31
+ spec.add_development_dependency 'rdoc'
32
+ spec.add_development_dependency 'redcarpet'
33
+ spec.add_development_dependency 'yard'
34
+
35
+ spec.add_development_dependency 'rubocop'
36
+ spec.add_development_dependency 'rubocop-rspec'
37
+ end
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack_session_manipulation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Stelfox
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-28 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
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: rake
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: rspec
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: capybara
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: coveralls
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
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rdoc
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: redcarpet
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: A rack middleware for exposing session state to tests.
182
+ email:
183
+ - sstelfox@bedroomprogrammers.net
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rspec"
190
+ - ".rubocop.yml"
191
+ - ".travis.yml"
192
+ - ".yardopts"
193
+ - CODE_OF_CONDUCT.md
194
+ - Gemfile
195
+ - LICENSE.txt
196
+ - README.md
197
+ - Rakefile
198
+ - lib/rack_session_manipulation.rb
199
+ - lib/rack_session_manipulation/capybara.rb
200
+ - lib/rack_session_manipulation/config.rb
201
+ - lib/rack_session_manipulation/middleware.rb
202
+ - lib/rack_session_manipulation/utilities.rb
203
+ - lib/rack_session_manipulation/version.rb
204
+ - rack_session_manipulation.gemspec
205
+ homepage: https://github.com/sstelfox/rack_session_manipulation
206
+ licenses:
207
+ - MIT
208
+ metadata: {}
209
+ post_install_message:
210
+ rdoc_options: []
211
+ require_paths:
212
+ - lib
213
+ required_ruby_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ required_rubygems_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ requirements: []
224
+ rubyforge_project:
225
+ rubygems_version: 2.4.3
226
+ signing_key:
227
+ specification_version: 4
228
+ summary: A rack middleware for exposing session state to tests.
229
+ test_files: []
230
+ has_rdoc: