helpstation 0.1.2 → 0.1.3
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/.rspec +2 -0
- data/Gemfile +5 -0
- data/Rakefile +4 -0
- data/lib/helpstation.rb +1 -0
- data/lib/helpstation/fetchers.rb +39 -0
- data/lib/helpstation/version.rb +1 -1
- data/spec/helpstation/processors/by_key_fetcher_spec.rb +41 -0
- data/spec/spec_helper.rb +18 -0
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10735e8d1c1287a67743aa8ebd1de5f608c93b34
|
4
|
+
data.tar.gz: c0e14bde4ea1682df121875a03a81b5192817bb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff51affc696814a260b1891684c229b29a54883f436b2ef594bb666777da66214f119adbbd759a4ab690c605404a89bcc70ad6b077fbd575d6f2b03ef9e9652b
|
7
|
+
data.tar.gz: 2e781d26a9cae27144de68e02cc6aa0677f12094e73f73b425f381135bc2cbf0378571386d3df51f10543ba79600acc3b5e93695421a7ff78182cc81d9dd121d
|
data/.rspec
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/helpstation.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative 'helpstation/action'
|
|
7
7
|
require_relative 'helpstation/observer'
|
8
8
|
require_relative 'helpstation/renderer'
|
9
9
|
require_relative 'helpstation/legacy_process'
|
10
|
+
require_relative 'helpstation/fetchers'
|
10
11
|
|
11
12
|
module Helpstation
|
12
13
|
def self.build_substation(env)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Helpstation
|
2
|
+
module Fetchers
|
3
|
+
NotFoundError = Class.new(StandardError)
|
4
|
+
|
5
|
+
class ByKeyFetcher < Processor
|
6
|
+
def self.build(input_key, output_key, &block)
|
7
|
+
Class.new(self) do
|
8
|
+
define_method :input_key do
|
9
|
+
input_key
|
10
|
+
end
|
11
|
+
define_method :output_key do
|
12
|
+
output_key
|
13
|
+
end
|
14
|
+
define_method :fetch do |input_value|
|
15
|
+
block.call input_value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def call
|
21
|
+
if input_value = input[input_key]
|
22
|
+
success(input.merge(output_key => fetch(input_value)))
|
23
|
+
else
|
24
|
+
error("#{input_key} must be present")
|
25
|
+
end
|
26
|
+
rescue NotFoundError
|
27
|
+
error("#{Inflecto.humanize(output_key)} ##{input_value} not found")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class ActiveRecordFetcher < ByKeyFetcher
|
32
|
+
def self.build(*)
|
33
|
+
super
|
34
|
+
rescue ActiveRecord::NotFoundError
|
35
|
+
raise NotFoundError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/helpstation/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Helpstation::Fetchers::ByKeyFetcher do
|
4
|
+
subject { processor.call request }
|
5
|
+
|
6
|
+
let(:processor) {
|
7
|
+
described_class.build(input_key, output_key) do
|
8
|
+
output
|
9
|
+
end
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:input_key) { :my_input }
|
13
|
+
let(:output_key) { :my_output }
|
14
|
+
let(:output) { "putting out" }
|
15
|
+
|
16
|
+
let(:request) { Substation::Request.new('my_request', env, input) }
|
17
|
+
|
18
|
+
context 'when input_key is present' do
|
19
|
+
let(:input) { { my_input: 'test' } }
|
20
|
+
|
21
|
+
it 'returns correct output' do
|
22
|
+
expect(subject).to be_a(Substation::Response::Success)
|
23
|
+
expect(subject.output).to eq(
|
24
|
+
my_input: input[:my_input],
|
25
|
+
my_output: output
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when input_key is not present' do
|
31
|
+
let(:input) { {} }
|
32
|
+
|
33
|
+
it 'returns error with appropriate message' do
|
34
|
+
expect(subject).to be_a(Substation::Response::Failure)
|
35
|
+
expect(subject.output).to eq(
|
36
|
+
success: false,
|
37
|
+
error: "#{input_key} must be present"
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'pry'
|
4
|
+
Bundler.setup
|
5
|
+
|
6
|
+
require 'helpstation'
|
7
|
+
|
8
|
+
Dir[File.dirname(__FILE__) + '/support/*.rb'].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
config.order = 'random'
|
14
|
+
|
15
|
+
def env(opts={})
|
16
|
+
@_env ||= {}
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helpstation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Indrek Juhkam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: substation
|
@@ -38,6 +38,7 @@ extensions: []
|
|
38
38
|
extra_rdoc_files: []
|
39
39
|
files:
|
40
40
|
- ".gitignore"
|
41
|
+
- ".rspec"
|
41
42
|
- ".ruby-gemset"
|
42
43
|
- ".ruby-version"
|
43
44
|
- Gemfile
|
@@ -48,11 +49,14 @@ files:
|
|
48
49
|
- lib/helpstation.rb
|
49
50
|
- lib/helpstation/action.rb
|
50
51
|
- lib/helpstation/evaluator.rb
|
52
|
+
- lib/helpstation/fetchers.rb
|
51
53
|
- lib/helpstation/legacy_process.rb
|
52
54
|
- lib/helpstation/observer.rb
|
53
55
|
- lib/helpstation/processor.rb
|
54
56
|
- lib/helpstation/renderer.rb
|
55
57
|
- lib/helpstation/version.rb
|
58
|
+
- spec/helpstation/processors/by_key_fetcher_spec.rb
|
59
|
+
- spec/spec_helper.rb
|
56
60
|
homepage: ''
|
57
61
|
licenses:
|
58
62
|
- MIT
|
@@ -73,8 +77,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
77
|
version: '0'
|
74
78
|
requirements: []
|
75
79
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.4.
|
80
|
+
rubygems_version: 2.4.5.1
|
77
81
|
signing_key:
|
78
82
|
specification_version: 4
|
79
83
|
summary: ''
|
80
|
-
test_files:
|
84
|
+
test_files:
|
85
|
+
- spec/helpstation/processors/by_key_fetcher_spec.rb
|
86
|
+
- spec/spec_helper.rb
|