actioninteractor 0.0.14 → 0.0.15
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/lib/action_interactor/base.rb +2 -11
 - data/lib/action_interactor/results.rb +22 -0
 - data/lib/actioninteractor.rb +6 -1
 - data/test/base_test.rb +1 -1
 - data/test/inheritance_test.rb +10 -9
 - data/test/results_test.rb +14 -0
 - metadata +5 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1cf59e621fd60a8cfb99220e97d08b679bc639a38d161e4c3254720969f761c6
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: bdbd3020978080ea42f44a17424c9f0ae71787ebd8fe37cbbe9e2b00569ea70a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d55546b260465dedecc262964d10001f2e12964af2d6bc2d35a4546eaa6aed91131c109590a86b68b901b7fdcb64d3b180a77c4df712e139ce839fd8ebe16691
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 01c4533072dd4020a359257e516b35fac8f80b316eadd2000e63de3b350aa81ae0d2f616357365fdecfadde5331bdad37cdc39a62b948448b39c0de4cd70323b
         
     | 
| 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module ActionInteractor
         
     | 
| 
       4 
4 
     | 
    
         
             
              class Base
         
     | 
| 
       5 
     | 
    
         
            -
                attr_reader :params, : 
     | 
| 
      
 5 
     | 
    
         
            +
                attr_reader :params, :results
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
                def initialize(params)
         
     | 
| 
       8 
8 
     | 
    
         
             
                  @params = params
         
     | 
| 
         @@ -40,7 +40,7 @@ module ActionInteractor 
     | 
|
| 
       40 
40 
     | 
    
         
             
                end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
                def reset!
         
     | 
| 
       43 
     | 
    
         
            -
                  @ 
     | 
| 
      
 43 
     | 
    
         
            +
                  @results = Results.new
         
     | 
| 
       44 
44 
     | 
    
         
             
                  @_success = false
         
     | 
| 
       45 
45 
     | 
    
         
             
                  @_finished = false
         
     | 
| 
       46 
46 
     | 
    
         
             
                end
         
     | 
| 
         @@ -54,21 +54,12 @@ module ActionInteractor 
     | 
|
| 
       54 
54 
     | 
    
         
             
                  @_success = true
         
     | 
| 
       55 
55 
     | 
    
         
             
                  @_finished = true
         
     | 
| 
       56 
56 
     | 
    
         
             
                end
         
     | 
| 
       57 
     | 
    
         
            -
                alias_method :finish!, :success!
         
     | 
| 
       58 
57 
     | 
    
         | 
| 
       59 
58 
     | 
    
         
             
                def fail!
         
     | 
| 
       60 
59 
     | 
    
         
             
                  @_success = false
         
     | 
| 
       61 
60 
     | 
    
         
             
                  @_finished = true
         
     | 
| 
       62 
61 
     | 
    
         
             
                end
         
     | 
| 
       63 
62 
     | 
    
         | 
| 
       64 
     | 
    
         
            -
                def add_result(key, value)
         
     | 
| 
       65 
     | 
    
         
            -
                  @result[key] = value
         
     | 
| 
       66 
     | 
    
         
            -
                end
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                def results(items = {})
         
     | 
| 
       69 
     | 
    
         
            -
                  @result = items
         
     | 
| 
       70 
     | 
    
         
            -
                end
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
63 
     | 
    
         
             
                class << self
         
     | 
| 
       73 
64 
     | 
    
         
             
                  def execute(params)
         
     | 
| 
       74 
65 
     | 
    
         
             
                    new(params).tap(&:execute)
         
     | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "forwardable"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module ActionInteractor
         
     | 
| 
      
 6 
     | 
    
         
            +
              class Results
         
     | 
| 
      
 7 
     | 
    
         
            +
                include Enumerable
         
     | 
| 
      
 8 
     | 
    
         
            +
                extend Forwardable
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                attr_reader :_results
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                def_delegators :@_results, :clear, :keys, :values, :[], :delete
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                def initialize(*)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @_results = {}
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def add(attribute, detail)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  _results[attribute.to_sym] = detail
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/actioninteractor.rb
    CHANGED
    
    
    
        data/test/base_test.rb
    CHANGED
    
    
    
        data/test/inheritance_test.rb
    CHANGED
    
    | 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "test/unit"
         
     | 
| 
       2 
     | 
    
         
            -
            require_relative "../lib/ 
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative "../lib/actioninteractor"
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            class User
         
     | 
| 
       5 
5 
     | 
    
         
             
              attr_accessor :name
         
     | 
| 
         @@ -12,16 +12,17 @@ end 
     | 
|
| 
       12 
12 
     | 
    
         
             
            class RegistrationInteractor < ActionInteractor::Base
         
     | 
| 
       13 
13 
     | 
    
         
             
              def execute
         
     | 
| 
       14 
14 
     | 
    
         
             
                return fail! unless params[:name]
         
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
       16 
     | 
    
         
            -
                 
     | 
| 
      
 15 
     | 
    
         
            +
                results.add(:user, User.new(name: params[:name]))
         
     | 
| 
      
 16 
     | 
    
         
            +
                success!
         
     | 
| 
       17 
17 
     | 
    
         
             
              end
         
     | 
| 
       18 
18 
     | 
    
         
             
            end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
            class NotificationInteractor < ActionInteractor::Base
         
     | 
| 
       21 
21 
     | 
    
         
             
              def execute
         
     | 
| 
       22 
22 
     | 
    
         
             
                return fail! unless params[:name] || params[:email]
         
     | 
| 
       23 
     | 
    
         
            -
                results( 
     | 
| 
       24 
     | 
    
         
            -
                 
     | 
| 
      
 23 
     | 
    
         
            +
                results.add(:name, params[:name])
         
     | 
| 
      
 24 
     | 
    
         
            +
                results.add(:email, params[:email])
         
     | 
| 
      
 25 
     | 
    
         
            +
                success!
         
     | 
| 
       25 
26 
     | 
    
         
             
              end
         
     | 
| 
       26 
27 
     | 
    
         
             
            end
         
     | 
| 
       27 
28 
     | 
    
         | 
| 
         @@ -41,13 +42,13 @@ class InheritanceTest < Test::Unit::TestCase 
     | 
|
| 
       41 
42 
     | 
    
         
             
              test "the result contains a user" do
         
     | 
| 
       42 
43 
     | 
    
         
             
                params = { name: 'John'}
         
     | 
| 
       43 
44 
     | 
    
         
             
                interactor = RegistrationInteractor.execute(params)
         
     | 
| 
       44 
     | 
    
         
            -
                assert_instance_of(User, interactor. 
     | 
| 
      
 45 
     | 
    
         
            +
                assert_instance_of(User, interactor.results[:user])
         
     | 
| 
       45 
46 
     | 
    
         
             
              end
         
     | 
| 
       46 
47 
     | 
    
         | 
| 
       47 
48 
     | 
    
         
             
              test "the result user name is John" do
         
     | 
| 
       48 
49 
     | 
    
         
             
                params = { name: 'John'}
         
     | 
| 
       49 
50 
     | 
    
         
             
                interactor = RegistrationInteractor.execute(params)
         
     | 
| 
       50 
     | 
    
         
            -
                user = interactor. 
     | 
| 
      
 51 
     | 
    
         
            +
                user = interactor.results[:user]
         
     | 
| 
       51 
52 
     | 
    
         
             
                assert_equal(user.name, 'John')
         
     | 
| 
       52 
53 
     | 
    
         
             
              end
         
     | 
| 
       53 
54 
     | 
    
         | 
| 
         @@ -78,9 +79,9 @@ class InheritanceTest < Test::Unit::TestCase 
     | 
|
| 
       78 
79 
     | 
    
         
             
              test "the result user name is Taro and email is taro@example.com" do
         
     | 
| 
       79 
80 
     | 
    
         
             
                params = { name: 'Taro', email: 'taro@example.com'}
         
     | 
| 
       80 
81 
     | 
    
         
             
                interactor = NotificationInteractor.execute(params)
         
     | 
| 
       81 
     | 
    
         
            -
                name = interactor. 
     | 
| 
      
 82 
     | 
    
         
            +
                name = interactor.results[:name]
         
     | 
| 
       82 
83 
     | 
    
         
             
                assert_equal(name, 'Taro')
         
     | 
| 
       83 
     | 
    
         
            -
                email = interactor. 
     | 
| 
      
 84 
     | 
    
         
            +
                email = interactor.results[:email]
         
     | 
| 
       84 
85 
     | 
    
         
             
                assert_equal(email, 'taro@example.com')
         
     | 
| 
       85 
86 
     | 
    
         
             
              end
         
     | 
| 
       86 
87 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "test/unit"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative "../lib/actioninteractor"
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            class ResultsTest < Test::Unit::TestCase
         
     | 
| 
      
 5 
     | 
    
         
            +
              test "initialized correctly" do
         
     | 
| 
      
 6 
     | 
    
         
            +
                assert_nothing_raised { ActionInteractor::Results.new }
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              test "add result for the key" do
         
     | 
| 
      
 10 
     | 
    
         
            +
                results = ActionInteractor::Results.new
         
     | 
| 
      
 11 
     | 
    
         
            +
                results.add(:foo, "bar")
         
     | 
| 
      
 12 
     | 
    
         
            +
                assert_equal(results[:foo], "bar")
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: actioninteractor
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.15
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Ryo Hashimoto
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2018- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-12-25 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -48,9 +48,11 @@ files: 
     | 
|
| 
       48 
48 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       49 
49 
     | 
    
         
             
            - actioninteractor.gemspec
         
     | 
| 
       50 
50 
     | 
    
         
             
            - lib/action_interactor/base.rb
         
     | 
| 
      
 51 
     | 
    
         
            +
            - lib/action_interactor/results.rb
         
     | 
| 
       51 
52 
     | 
    
         
             
            - lib/actioninteractor.rb
         
     | 
| 
       52 
53 
     | 
    
         
             
            - test/base_test.rb
         
     | 
| 
       53 
54 
     | 
    
         
             
            - test/inheritance_test.rb
         
     | 
| 
      
 55 
     | 
    
         
            +
            - test/results_test.rb
         
     | 
| 
       54 
56 
     | 
    
         
             
            homepage: https://github.com/ryohashimoto/lightrails
         
     | 
| 
       55 
57 
     | 
    
         
             
            licenses:
         
     | 
| 
       56 
58 
     | 
    
         
             
            - MIT
         
     | 
| 
         @@ -79,3 +81,4 @@ summary: Action Interactor provides a simple interface for performing operations 
     | 
|
| 
       79 
81 
     | 
    
         
             
            test_files:
         
     | 
| 
       80 
82 
     | 
    
         
             
            - test/base_test.rb
         
     | 
| 
       81 
83 
     | 
    
         
             
            - test/inheritance_test.rb
         
     | 
| 
      
 84 
     | 
    
         
            +
            - test/results_test.rb
         
     |