sliver 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01a74a1104ce1713e00244f93d3ad2e67817992f
4
- data.tar.gz: 4e39d179e03349cf5c5773a10afb345c18b81b22
3
+ metadata.gz: fe4e83efcb34646cfb507ccc74056fb402265f77
4
+ data.tar.gz: f52c128bb56392cd35d97940845c17e1f23fa1cc
5
5
  SHA512:
6
- metadata.gz: 3ad1ca7c87d8250f4d664e1ea5fb4f698e822780cd2715e370a05413aab4d858e68bc9d8e9d20d6f46bd61a5e114c6462e5280013f41362d9bf141fdb03548ff
7
- data.tar.gz: 4093e264929558478d157796a2c8b8bc108e531bae2c58b2ddf40d1912af78658980c2109a06719ebd8da2977e6ba35ea68f16c84812d048f7a22606bce6c84a
6
+ metadata.gz: e9b69f9c741d49387772a373cf6db8eab0dc39fcd9f49df34aa21b86cd54e344434c3d1e2b28f612cdc835fc2035643f73d9fd4fb5784924a551a5ed04a64832
7
+ data.tar.gz: bb79a247fddbe76eacc5cb0b07a6fe9ed681cd9ad96a318ccc6ab70fc2e2aa4f21e4c95f07de5a9e08ecc2118571b9685d9eff437c303e151fa31787a5ae0e26
@@ -1,5 +1,9 @@
1
1
  language: ruby
2
+ before_script:
3
+ - ((ruby --version | grep -q "2.4.1") && export RUBYOPT="--enable-frozen-string-literal") || true
2
4
  script: bundle exec rspec spec
3
5
  cache: bundler
4
6
  rvm:
5
- - 2.1
7
+ - 2.2
8
+ - 2.3.4
9
+ - 2.4.1
data/Gemfile CHANGED
@@ -1,3 +1,13 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ %w[
6
+ rspec
7
+ rspec-core
8
+ rspec-expectations
9
+ rspec-mocks
10
+ rspec-support
11
+ ].each do |library|
12
+ gem library, :git => "https://github.com/rspec/#{library}.git"
13
+ end
data/README.md CHANGED
@@ -20,7 +20,7 @@ Ruby doesn't lack for web frameworks, especially ones focused on APIs, but Slive
20
20
  Add it to your Gemfile like any other gem, or install it manually.
21
21
 
22
22
  ```ruby
23
- gem 'sliver', '~> 0.2.3'
23
+ gem 'sliver', '~> 0.2.4'
24
24
  ```
25
25
 
26
26
  ## Usage
@@ -1,5 +1,5 @@
1
1
  module Sliver
2
- #
2
+ PATH_KEY = "sliver.path".freeze
3
3
  end
4
4
 
5
5
  require 'sliver/action'
@@ -34,6 +34,6 @@ module Sliver::Action
34
34
  attr_reader :environment, :response
35
35
 
36
36
  def path_params
37
- @path_params ||= environment['sliver.path'].to_params environment
37
+ @path_params ||= environment[Sliver::PATH_KEY].to_params environment
38
38
  end
39
39
  end
@@ -1,6 +1,5 @@
1
1
  class Sliver::API
2
- NOT_FOUND_RESPONSE = [404, {'X-Cascade' => 'pass'}, ['Not Found']].freeze
3
- NOT_FOUND = lambda { |environment| NOT_FOUND_RESPONSE }
2
+ NOT_FOUND = [404, {'X-Cascade' => 'pass'}, ['Not Found']].freeze
4
3
 
5
4
  def initialize(&block)
6
5
  @endpoints = Sliver::Endpoints.new
@@ -11,7 +10,7 @@ class Sliver::API
11
10
  def call(environment)
12
11
  endpoint = endpoints.find environment
13
12
 
14
- endpoint.nil? ? NOT_FOUND.call(environment) : invoke(endpoint, environment)
13
+ endpoint.nil? ? NOT_FOUND : invoke(endpoint, environment)
15
14
  end
16
15
 
17
16
  def invoke(endpoint, environment)
@@ -11,7 +11,7 @@ class Sliver::Endpoints
11
11
  key = paths.keys.detect { |key| key.matches?(environment) }
12
12
  return nil unless key
13
13
 
14
- environment['sliver.path'] = key
14
+ environment[Sliver::PATH_KEY] = key
15
15
  paths[key]
16
16
  end
17
17
 
@@ -1,4 +1,8 @@
1
1
  class Sliver::Hook
2
+ def self.call(action, response)
3
+ new(action, response).call
4
+ end
5
+
2
6
  def initialize(action, response)
3
7
  @action, @response = action, response
4
8
  end
@@ -1,4 +1,9 @@
1
1
  class Sliver::Path
2
+ METHOD_KEY = "REQUEST_METHOD".freeze
3
+ PATH_KEY = "PATH_INFO".freeze
4
+ EMPTY_PATH = "".freeze
5
+ ROOT_PATH = "/".freeze
6
+
2
7
  attr_reader :http_method, :string
3
8
 
4
9
  def initialize(http_method, string)
@@ -11,12 +16,12 @@ class Sliver::Path
11
16
  end
12
17
 
13
18
  def hash
14
- "#{http_method} #{string}".hash
19
+ @hash ||= "#{http_method} #{string}".hash
15
20
  end
16
21
 
17
22
  def matches?(environment)
18
- method = environment['REQUEST_METHOD']
19
- path = normalised_path environment['PATH_INFO']
23
+ method = environment[METHOD_KEY]
24
+ path = normalised_path environment[PATH_KEY]
20
25
 
21
26
  http_method == method && path[string_to_regexp]
22
27
  end
@@ -24,7 +29,7 @@ class Sliver::Path
24
29
  def to_params(environment)
25
30
  return {} unless matches?(environment)
26
31
 
27
- path = normalised_path environment['PATH_INFO']
32
+ path = normalised_path environment[PATH_KEY]
28
33
  values = path.scan(string_to_regexp).flatten
29
34
 
30
35
  string_keys.each_with_index.inject({}) do |hash, (key, index)|
@@ -36,7 +41,7 @@ class Sliver::Path
36
41
  private
37
42
 
38
43
  def normalised_path(string)
39
- string == '' ? '/' : string
44
+ string == EMPTY_PATH ? ROOT_PATH : string
40
45
  end
41
46
 
42
47
  def string_keys
@@ -45,11 +45,7 @@ class Sliver::Runner
45
45
  end
46
46
 
47
47
  def post_process
48
- processors.each { |processor| processor.call }
49
- end
50
-
51
- def processors
52
- klass.processors.collect { |klass| klass.new action, response }
48
+ klass.processors.each { |processor| processor.call action, response }
53
49
  end
54
50
 
55
51
  def response
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'sliver'
4
- spec.version = '0.2.3'
4
+ spec.version = '0.2.4'
5
5
  spec.authors = ['Pat Allan']
6
6
  spec.email = ['pat@freelancing-gods.com']
7
7
  spec.summary = %q{Lightweight, simple Rack APIs}
@@ -17,5 +17,5 @@ Gem::Specification.new do |spec|
17
17
  spec.add_runtime_dependency 'rack', '>= 1.5.2'
18
18
 
19
19
  spec.add_development_dependency 'rack-test', '>= 0.6.2'
20
- spec.add_development_dependency 'rspec', '>= 3.0.0.beta2'
20
+ spec.add_development_dependency 'rspec', '>= 3.6.0'
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sliver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-21 00:00:00.000000000 Z
11
+ date: 2017-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.0.beta2
47
+ version: 3.6.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0.beta2
54
+ version: 3.6.0
55
55
  description: A super simple, object-focused extendable Rack API.
56
56
  email:
57
57
  - pat@freelancing-gods.com