farah 0.1.0 → 0.2.0

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: 263fc057737c09addca0efa70b5eaee932c6af6a
4
- data.tar.gz: 13335817e964656a896ca9bc0be6b81601fd0e1f
3
+ metadata.gz: e828bce0fd5655a3f8c9ede3c673b44bc9ede83e
4
+ data.tar.gz: 4d10b0c3b6c76cbd3b9a63cf35812f741390582f
5
5
  SHA512:
6
- metadata.gz: bf82066b3bf7fdf6dd906e5a847e819348b88798fa014d59be407c8640b08ce6d42d0c14c6910d11e860979796e5f00d0f1578035315811b4fab26f768748078
7
- data.tar.gz: 52ecb0e02a27a72fb843656e28260bbab0a4423ac508d0bf36b9afeafc1901843feaf69c64ff2b071cbd0764a6126c0aa92d4ad2b751547c0a8dea574999439d
6
+ metadata.gz: 9f6889814563bedbb63a3f7e40d0876c8d006fc213c2a3e1de7ad8359050145ccaba7c5b9f31f8e3a695fe6830cc8a03d94542c35bcfe93a0a27c3e70f18e832
7
+ data.tar.gz: 2b6a092ae68913fea62f407faaab8adef1621f827cae7d1873160089943e2f2b762c3b7355ad55f2269088384c56b1baae4cfe9fd1d1d7f60c33b23c6e739386
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Steven Weiss
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.
@@ -0,0 +1,29 @@
1
+ # Farah
2
+
3
+ Farah is a tiny library for implementing "runners" (service objects).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'farah'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install farah
20
+
21
+ For RubyMotion, require the gem inside your Gemfile:
22
+
23
+ ```ruby
24
+ require 'farah'
25
+ ```
26
+
27
+ ## License
28
+
29
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,5 @@
1
+ task :spec do
2
+ Dir.glob('./spec/**/*_spec.rb').each { |file| require file }
3
+ end
4
+
5
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ require_relative './lib/farah/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'farah'
5
+ s.summary = 'Farah'
6
+ s.version = Farah::VERSION
7
+ s.authors = ['Steve Weiss']
8
+ s.email = ['weissst@mail.gvsu.edu']
9
+ s.homepage = 'https://github.com/sirscriptalot/farah'
10
+ s.license = 'MIT'
11
+ s.files = `git ls-files`.split("\n")
12
+ end
@@ -0,0 +1,60 @@
1
+ module Farah
2
+ module Helpers
3
+ def start(klass, action, *args)
4
+ klass.new(self, action).call(*args)
5
+ end
6
+ end
7
+
8
+ module Results
9
+ class Result
10
+ attr_reader :payload
11
+
12
+ def initialize(payload)
13
+ @payload = payload
14
+ end
15
+ end
16
+
17
+ class Success < Result
18
+ def success?
19
+ true
20
+ end
21
+
22
+ def failure?
23
+ false
24
+ end
25
+ end
26
+
27
+ class Failure < Result
28
+ def success?
29
+ false
30
+ end
31
+
32
+ def failure?
33
+ true
34
+ end
35
+ end
36
+ end
37
+
38
+ class Runner
39
+ def initialize(context, action)
40
+ @context = context
41
+ @action = action
42
+ end
43
+
44
+ def call(*args)
45
+ catch(:finish) { send(action, *args) }
46
+ end
47
+
48
+ private
49
+
50
+ attr_reader :context, :action
51
+
52
+ def success!(payload)
53
+ throw :finish, Results::Success.new(payload)
54
+ end
55
+
56
+ def failure!(payload)
57
+ throw :finish, Results::Failure.new(payload)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Farah
2
+ VERSION = '0.2.0'.freeze
3
+ end
@@ -0,0 +1,74 @@
1
+ require_relative './spec_helper'
2
+
3
+ module Runners
4
+ include Farah::Helpers
5
+
6
+ class Foo < Farah::Runner
7
+ def bar(sym)
8
+ success!('success!') if sym == :bar
9
+ failure!('failure!')
10
+ end
11
+
12
+ def qux(value)
13
+ value
14
+ end
15
+ end
16
+ end
17
+
18
+ class Controller
19
+ include Runners
20
+
21
+ attr_reader :success, :failure
22
+
23
+ def initialize
24
+ @success = nil
25
+ @failure = nil
26
+ end
27
+
28
+ def call(value)
29
+ start(Foo, :bar, value)
30
+ end
31
+ end
32
+
33
+ describe 'Farah::Helpers' do
34
+ before do
35
+ @controller = Controller.new
36
+ end
37
+
38
+ describe '#start' do
39
+ it 'calls action on runner with value' do
40
+ value = '123'
41
+
42
+ assert_equal @controller.start(Runners::Foo, :qux, value), value
43
+ end
44
+ end
45
+ end
46
+
47
+ describe 'Farah::Runner' do
48
+ before do
49
+ @controller = Controller.new
50
+ end
51
+
52
+ describe '#success!' do
53
+ it 'sends payload with result' do
54
+ result = @controller.call(:bar)
55
+
56
+ assert result.success?
57
+ assert_equal result.payload, 'success!'
58
+ end
59
+ end
60
+
61
+ describe '#failure!' do
62
+ def @controller.bar
63
+ failure!('failure!') unless sym == :bar
64
+ success!('success!')
65
+ end
66
+
67
+ it 'sends payload with result' do
68
+ result = @controller.call(:baz)
69
+
70
+ assert result.failure?
71
+ assert_equal result.payload, 'failure!'
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,6 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/farah'
3
+
4
+ def context(*args, &block)
5
+ describe(*args, &block)
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: farah
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Weiss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-30 00:00:00.000000000 Z
11
+ date: 2016-12-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -16,7 +16,17 @@ email:
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
- files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - farah.gemspec
26
+ - lib/farah.rb
27
+ - lib/farah/version.rb
28
+ - spec/farah_spec.rb
29
+ - spec/spec_helper.rb
20
30
  homepage: https://github.com/sirscriptalot/farah
21
31
  licenses:
22
32
  - MIT