sinatra_bicyclist 0.1.0 → 0.2.0.pre1
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/sinatra/bicyclist/cycle.rb +40 -0
- data/lib/sinatra/bicyclist/cycler.rb +7 -17
- data/lib/sinatra/bicyclist/version.rb +1 -1
- data/spec/byciclist_spec.rb +1 -1
- data/spec/cycle_spec.rb +45 -0
- data/spec/cycler_spec.rb +0 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5c2a1d3397cf39b0a76a57869621bcae9ef7449
|
4
|
+
data.tar.gz: 6d9f76a78fbf2eff1fcba489ce496452431c1b23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0e5f2df39d9fc6c165569eb4e3d4ee6b0c7d8483839372f0eaa85a1a0712642f6df2d823051f03b5c75d33a1911e2557b11b59a6c563d8739518ad552ab2a12
|
7
|
+
data.tar.gz: 8974ef82cdfae4a3df2c8bd31c64c1289f8bdb2c8ae47335fc58c291aeb02e00324e521475be37a77cbd27eba26b30871c40038bc177a612a35b6f56d97b06d2
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## 0.2.0 - 2014-10-07
|
5
|
+
### Added
|
6
|
+
- added `Sinatra::Bicyclist::Cycle` that handles cycling the session
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
- moved methods that require session from `Sinatra::Bicyclist::Cycler` to `Sinatra::Bicyclist::Cycle`
|
10
|
+
|
4
11
|
## 0.1.0 - 2014-09-30
|
5
12
|
### Added
|
6
13
|
- support for more cycle groups
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Sinatra
|
2
|
+
module Bicyclist
|
3
|
+
class Cycle
|
4
|
+
def initialize(session)
|
5
|
+
@session = session
|
6
|
+
end
|
7
|
+
|
8
|
+
def page_index
|
9
|
+
@session[:_cycle_page_index] ||= -1
|
10
|
+
end
|
11
|
+
|
12
|
+
def next_index
|
13
|
+
page_index.succ
|
14
|
+
end
|
15
|
+
|
16
|
+
def page_index=(value)
|
17
|
+
@session[:_cycle_page_index] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_index
|
21
|
+
@session[:_cycle_page_index] = -1
|
22
|
+
end
|
23
|
+
|
24
|
+
def last_cycle
|
25
|
+
@session[:_last_cycle].to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def page(pages)
|
29
|
+
index = next_route(pages)
|
30
|
+
pages[index]
|
31
|
+
end
|
32
|
+
|
33
|
+
def next_route(pages)
|
34
|
+
routes = pages.length
|
35
|
+
|
36
|
+
self.page_index = next_index % routes
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
|
+
require_relative 'cycle'
|
2
|
+
|
1
3
|
module Sinatra
|
2
4
|
module Bicyclist
|
3
5
|
class Cycler
|
4
6
|
attr_accessor :duration
|
5
7
|
|
6
|
-
def initialize(settings)
|
8
|
+
def initialize(settings, cycle_class = Bicyclist::Cycle)
|
7
9
|
@settings = settings
|
10
|
+
@cycle_class = cycle_class
|
8
11
|
end
|
9
12
|
|
10
13
|
def routes
|
@@ -32,23 +35,10 @@ module Sinatra
|
|
32
35
|
has_groups?
|
33
36
|
end
|
34
37
|
|
35
|
-
def page_index(session)
|
36
|
-
page_index = session[:_cycle_page_index] || -1
|
37
|
-
session[:_cycle_page_index] = page_index + 1
|
38
|
-
end
|
39
|
-
|
40
|
-
def random_route(session, group)
|
41
|
-
number_of_routes = pages(group).length
|
42
|
-
pages(group)[page_index(session) % number_of_routes]
|
43
|
-
end
|
44
|
-
|
45
|
-
def reset_index(session)
|
46
|
-
session[:_cycle_page_index] = -1
|
47
|
-
end
|
48
|
-
|
49
38
|
def page(session, group = nil)
|
50
|
-
|
51
|
-
|
39
|
+
cycle = @cycle_class.new(session)
|
40
|
+
cycle.reset_index unless cycle.last_cycle == group.to_s
|
41
|
+
page = cycle.page pages(group)
|
52
42
|
session[:_cycle] = group || (has_groups? && page)
|
53
43
|
page
|
54
44
|
end
|
data/spec/byciclist_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'sinatra'
|
2
2
|
require 'sinatra/bicyclist'
|
3
3
|
|
4
|
+
set :environment, :test
|
4
5
|
set :routes_to_cycle_through, {
|
5
6
|
one: [:foo],
|
6
7
|
two: [:bar, :baz]
|
@@ -15,7 +16,6 @@ RSpec.describe Sinatra::Application do
|
|
15
16
|
it { expect(response.status).to eq(302) }
|
16
17
|
it { expect(response.headers).to include('Location' => 'http://example.org/_cycle/one') }
|
17
18
|
|
18
|
-
|
19
19
|
context 'two' do
|
20
20
|
before { get '/_cycle/two' }
|
21
21
|
|
data/spec/cycle_spec.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
RSpec.describe Sinatra::Bicyclist::Cycle do
|
2
|
+
let(:routes) { ['a', 'b'] }
|
3
|
+
let(:session) { Hash.new }
|
4
|
+
subject(:cycle) { described_class.new(session) }
|
5
|
+
|
6
|
+
it 'cycles page' do
|
7
|
+
page = cycle.page(routes)
|
8
|
+
expect(page).to eq('a')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'cycles all page' do
|
12
|
+
pages = 2.times.map { cycle.page(routes) }
|
13
|
+
expect(pages).to eq(['a', 'b'])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has -1 index' do
|
17
|
+
expect(cycle.page_index).to eq(-1)
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'cycled page' do
|
21
|
+
let!(:page) { cycle.page(routes) }
|
22
|
+
before { page }
|
23
|
+
|
24
|
+
it 'changes the index' do
|
25
|
+
expect(cycle.page_index).to eq(0)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'looped page' do
|
30
|
+
let(:first) { cycle.page(routes) }
|
31
|
+
let(:second) { cycle.page(routes) }
|
32
|
+
let(:third) { cycle.page(routes) }
|
33
|
+
|
34
|
+
it 'loops index' do
|
35
|
+
expect(cycle.page_index).to eq(-1)
|
36
|
+
expect(first).to eq('a')
|
37
|
+
expect(cycle.page_index).to eq(0)
|
38
|
+
expect(second).to eq('b')
|
39
|
+
expect(cycle.page_index).to eq(1)
|
40
|
+
expect(third).to eq('a')
|
41
|
+
expect(cycle.page_index).to eq(0)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/spec/cycler_spec.rb
ADDED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_bicyclist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Lavrisha
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -87,10 +87,13 @@ files:
|
|
87
87
|
- examples/config.ru
|
88
88
|
- examples/modular_application.rb
|
89
89
|
- lib/sinatra/bicyclist.rb
|
90
|
+
- lib/sinatra/bicyclist/cycle.rb
|
90
91
|
- lib/sinatra/bicyclist/cycler.rb
|
91
92
|
- lib/sinatra/bicyclist/version.rb
|
92
93
|
- sinatra_cyclist.gemspec
|
93
94
|
- spec/byciclist_spec.rb
|
95
|
+
- spec/cycle_spec.rb
|
96
|
+
- spec/cycler_spec.rb
|
94
97
|
- spec/spec_helper.rb
|
95
98
|
- spec/support/rack.rb
|
96
99
|
homepage: https://github.com/mikz/sinatra_bicyclist
|
@@ -107,9 +110,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
110
|
version: '0'
|
108
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
112
|
requirements:
|
110
|
-
- - "
|
113
|
+
- - ">"
|
111
114
|
- !ruby/object:Gem::Version
|
112
|
-
version:
|
115
|
+
version: 1.3.1
|
113
116
|
requirements: []
|
114
117
|
rubyforge_project:
|
115
118
|
rubygems_version: 2.2.2
|
@@ -118,5 +121,7 @@ specification_version: 4
|
|
118
121
|
summary: Sinatra can ride a bicycle over and over and over again
|
119
122
|
test_files:
|
120
123
|
- spec/byciclist_spec.rb
|
124
|
+
- spec/cycle_spec.rb
|
125
|
+
- spec/cycler_spec.rb
|
121
126
|
- spec/spec_helper.rb
|
122
127
|
- spec/support/rack.rb
|