helpstation 0.1.2 → 0.1.3

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: 9cceaab45a14e7a0acfdcdd1bbaeef1cc2376ee0
4
- data.tar.gz: 1ce5b5603b3f88525659746a292586bfca6ef009
3
+ metadata.gz: 10735e8d1c1287a67743aa8ebd1de5f608c93b34
4
+ data.tar.gz: c0e14bde4ea1682df121875a03a81b5192817bb4
5
5
  SHA512:
6
- metadata.gz: 15c04bc9d11bc1ff196864b2421266552e1dd448ecf1a6f564d640f0cc238339cef91acfa085ab483bad35db14e7592d95c84298457de76e9c186606292aa567
7
- data.tar.gz: 27719e478e3192391902a89306fd585def4d415884159b972ca7d587d8b6fb52911f570cacbd27f0bf9ea5a24b81bd8df272f693121160087af8839471da6e87
6
+ metadata.gz: ff51affc696814a260b1891684c229b29a54883f436b2ef594bb666777da66214f119adbbd759a4ab690c605404a89bcc70ad6b077fbd575d6f2b03ef9e9652b
7
+ data.tar.gz: 2e781d26a9cae27144de68e02cc6aa0677f12094e73f73b425f381135bc2cbf0378571386d3df51f10543ba79600acc3b5e93695421a7ff78182cc81d9dd121d
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile CHANGED
@@ -2,5 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rake'
4
4
 
5
+ group :test, :development do
6
+ gem 'rspec'
7
+ gem 'pry-byebug'
8
+ end
9
+
5
10
  # Specify your gem's dependencies in helpstation.gemspec
6
11
  gemspec
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task default: :spec
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Helpstation
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -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
@@ -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.2
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-14 00:00:00.000000000 Z
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.2
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