yep 0.0.0 → 3.0.2
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/.rubocop.yml +6 -2
 - data/.ruby-version +1 -1
 - data/Gemfile.lock +19 -18
 - data/README.md +38 -13
 - data/lib/yep/version.rb +1 -1
 - data/test/test_yep.rb +3 -0
 - data/yep.gemspec +2 -0
 - metadata +5 -5
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: b940c82007e745b1f117e984e1d1d6a5b482a4b5901d266dcd18b5d550769266
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 0a81b6fae45ceee23e8a54513a9a47adc1a5dec83b84a2c74f498c303682c462
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 93682d1d007e3f722525e24e33cca67074d2054d3d009db7149362fd7167f8feafeb9bbbda573137049bf913d34f46ee6322610fe0d6e01d6d85c0df64137f0f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: de8e87d2e85cdd2dd2f5d5325de2608b16a17bf69fe2b3aec268dc831ea724214afe0ae7a2e43a76e232c2241cef687c6cb465173bbf42a300c1ad357c087f79
         
     | 
    
        data/.rubocop.yml
    CHANGED
    
    | 
         @@ -1,5 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            AllCops:
         
     | 
| 
       2 
     | 
    
         
            -
              TargetRubyVersion: 2 
     | 
| 
      
 2 
     | 
    
         
            +
              TargetRubyVersion: 3.0.2
         
     | 
| 
      
 3 
     | 
    
         
            +
              NewCops: enable
         
     | 
| 
       3 
4 
     | 
    
         
             
            Metrics/LineLength:
         
     | 
| 
       4 
5 
     | 
    
         
             
              Max: 100
         
     | 
| 
       5 
6 
     | 
    
         
             
            Style/Documentation:
         
     | 
| 
         @@ -14,7 +15,10 @@ Metrics/ModuleLength: 
     | 
|
| 
       14 
15 
     | 
    
         
             
            Metrics/BlockLength:
         
     | 
| 
       15 
16 
     | 
    
         
             
              Exclude:
         
     | 
| 
       16 
17 
     | 
    
         
             
                - "**/*test_*.rb"
         
     | 
| 
       17 
     | 
    
         
            -
            Lint/ 
     | 
| 
      
 18 
     | 
    
         
            +
            Lint/BinaryOperatorWithIdenticalOperands:
         
     | 
| 
      
 19 
     | 
    
         
            +
              Exclude:
         
     | 
| 
      
 20 
     | 
    
         
            +
                - "**/*test_*.rb"
         
     | 
| 
      
 21 
     | 
    
         
            +
            Lint/IdentityComparison:
         
     | 
| 
       18 
22 
     | 
    
         
             
              Exclude:
         
     | 
| 
       19 
23 
     | 
    
         
             
                - "**/*test_*.rb"
         
     | 
| 
       20 
24 
     | 
    
         
             
            Layout/MultilineOperationIndentation:
         
     | 
    
        data/.ruby-version
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            3.0.2
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -1,37 +1,38 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            PATH
         
     | 
| 
       2 
2 
     | 
    
         
             
              remote: .
         
     | 
| 
       3 
3 
     | 
    
         
             
              specs:
         
     | 
| 
       4 
     | 
    
         
            -
                yep ( 
     | 
| 
      
 4 
     | 
    
         
            +
                yep (3.0.2)
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            GEM
         
     | 
| 
       7 
7 
     | 
    
         
             
              remote: http://rubygems.org/
         
     | 
| 
       8 
8 
     | 
    
         
             
              specs:
         
     | 
| 
       9 
     | 
    
         
            -
                ast (2.4. 
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  ast (~> 2.4.0)
         
     | 
| 
       14 
     | 
    
         
            -
                powerpack (0.1.2)
         
     | 
| 
       15 
     | 
    
         
            -
                psych (3.1.0)
         
     | 
| 
      
 9 
     | 
    
         
            +
                ast (2.4.2)
         
     | 
| 
      
 10 
     | 
    
         
            +
                parallel (1.21.0)
         
     | 
| 
      
 11 
     | 
    
         
            +
                parser (3.0.2.0)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  ast (~> 2.4.1)
         
     | 
| 
       16 
13 
     | 
    
         
             
                rainbow (3.0.0)
         
     | 
| 
       17 
     | 
    
         
            -
                 
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                regexp_parser (2.1.1)
         
     | 
| 
      
 15 
     | 
    
         
            +
                rexml (3.2.5)
         
     | 
| 
      
 16 
     | 
    
         
            +
                rubocop (1.22.3)
         
     | 
| 
       19 
17 
     | 
    
         
             
                  parallel (~> 1.10)
         
     | 
| 
       20 
     | 
    
         
            -
                  parser (>=  
     | 
| 
       21 
     | 
    
         
            -
                  powerpack (~> 0.1)
         
     | 
| 
       22 
     | 
    
         
            -
                  psych (>= 3.1.0)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  parser (>= 3.0.0.0)
         
     | 
| 
       23 
19 
     | 
    
         
             
                  rainbow (>= 2.2.2, < 4.0)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  regexp_parser (>= 1.8, < 3.0)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  rexml
         
     | 
| 
      
 22 
     | 
    
         
            +
                  rubocop-ast (>= 1.12.0, < 2.0)
         
     | 
| 
       24 
23 
     | 
    
         
             
                  ruby-progressbar (~> 1.7)
         
     | 
| 
       25 
     | 
    
         
            -
                  unicode-display_width ( 
     | 
| 
       26 
     | 
    
         
            -
                 
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
                  unicode-display_width (>= 1.4.0, < 3.0)
         
     | 
| 
      
 25 
     | 
    
         
            +
                rubocop-ast (1.13.0)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  parser (>= 3.0.1.1)
         
     | 
| 
      
 27 
     | 
    
         
            +
                ruby-progressbar (1.11.0)
         
     | 
| 
      
 28 
     | 
    
         
            +
                unicode-display_width (2.1.0)
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
30 
     | 
    
         
             
            PLATFORMS
         
     | 
| 
       30 
     | 
    
         
            -
               
     | 
| 
      
 31 
     | 
    
         
            +
              x86_64-linux
         
     | 
| 
       31 
32 
     | 
    
         | 
| 
       32 
33 
     | 
    
         
             
            DEPENDENCIES
         
     | 
| 
       33 
34 
     | 
    
         
             
              rubocop
         
     | 
| 
       34 
35 
     | 
    
         
             
              yep!
         
     | 
| 
       35 
36 
     | 
    
         | 
| 
       36 
37 
     | 
    
         
             
            BUNDLED WITH
         
     | 
| 
       37 
     | 
    
         
            -
               2. 
     | 
| 
      
 38 
     | 
    
         
            +
               2.2.22
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -19,7 +19,7 @@ gem 'yep' 
     | 
|
| 
       19 
19 
     | 
    
         
             
            ## Usage
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
            In the following example we will use a simple convoluted application that
         
     | 
| 
       22 
     | 
    
         
            -
            queries an external API for  
     | 
| 
      
 22 
     | 
    
         
            +
            queries an external API for user data.
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
            ```ruby
         
     | 
| 
       25 
25 
     | 
    
         
             
            require 'net/http'
         
     | 
| 
         @@ -48,18 +48,22 @@ end 
     | 
|
| 
       48 
48 
     | 
    
         
             
            ```
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
            The problem with the code above is that the `User` class has a hard dependency
         
     | 
| 
       51 
     | 
    
         
            -
            on `RandomUserRepository`. This has two negative side effects.  
     | 
| 
       52 
     | 
    
         
            -
            simple in a larger application to swap out the `RandomUserRepository` for
         
     | 
| 
       53 
     | 
    
         
            -
            another underlying repository such as `SqlUserRepository`. It's not simple
         
     | 
| 
       54 
     | 
    
         
            -
            to swap out the `RandomUserRepository` for testing purposes, maybe for
         
     | 
| 
       55 
     | 
    
         
            -
            something like `TestUserRepository`.
         
     | 
| 
      
 51 
     | 
    
         
            +
            on the `RandomUserRepository`. This has two negative side effects. 
         
     | 
| 
       56 
52 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
      
 53 
     | 
    
         
            +
            It would not be simple in a larger application to swap out the
         
     | 
| 
      
 54 
     | 
    
         
            +
            `RandomUserRepository` and all the places it ends up being littered throughout
         
     | 
| 
      
 55 
     | 
    
         
            +
            the application for another implementation of the repository such as
         
     | 
| 
      
 56 
     | 
    
         
            +
            `SqlUserRepository`. 
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            It would not be simple and concise to swap out the `RandomUserRepository` for
         
     | 
| 
      
 59 
     | 
    
         
            +
            testing purposes, maybe for something like a `TestUserRepository`.
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            So lets have a look at dependency injection with `yep` to see how this can be
         
     | 
| 
       58 
62 
     | 
    
         
             
            solved.
         
     | 
| 
       59 
63 
     | 
    
         | 
| 
       60 
64 
     | 
    
         
             
            ### Container
         
     | 
| 
       61 
65 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
            The container will  
     | 
| 
      
 66 
     | 
    
         
            +
            The container will store dependencies registered under keys which can then later
         
     | 
| 
       63 
67 
     | 
    
         
             
            be resolved. Registration of dependencies should happen once for an application.
         
     | 
| 
       64 
68 
     | 
    
         | 
| 
       65 
69 
     | 
    
         
             
            ```ruby
         
     | 
| 
         @@ -77,8 +81,8 @@ end 
     | 
|
| 
       77 
81 
     | 
    
         
             
            App.boot
         
     | 
| 
       78 
82 
     | 
    
         
             
            ```
         
     | 
| 
       79 
83 
     | 
    
         | 
| 
       80 
     | 
    
         
            -
            During  
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
      
 84 
     | 
    
         
            +
            During boot we register classes under a keys then assign a lifetime to the
         
     | 
| 
      
 85 
     | 
    
         
            +
            registered classes. 
         
     | 
| 
       82 
86 
     | 
    
         | 
| 
       83 
87 
     | 
    
         
             
            If `Yep::Container::SINGLETON` is used as a lifetime, every time the dependency
         
     | 
| 
       84 
88 
     | 
    
         
             
            is resolved the container will return the same instance of a class.
         
     | 
| 
         @@ -114,7 +118,7 @@ registered dependency, in this case `repository`. Now by calling 
     | 
|
| 
       114 
118 
     | 
    
         
             
            container.
         
     | 
| 
       115 
119 
     | 
    
         | 
| 
       116 
120 
     | 
    
         
             
            If at anytime you wanted to swap out and use a different repository, as long
         
     | 
| 
       117 
     | 
    
         
            -
            as it has the same method signatures and  
     | 
| 
      
 121 
     | 
    
         
            +
            as it has the same method signatures and returns the same data structures, you
         
     | 
| 
       118 
122 
     | 
    
         
             
            can just change the dependency on the container.
         
     | 
| 
       119 
123 
     | 
    
         | 
| 
       120 
124 
     | 
    
         
             
            Example:
         
     | 
| 
         @@ -123,7 +127,7 @@ A new repository that reads from a SQL database. 
     | 
|
| 
       123 
127 
     | 
    
         | 
| 
       124 
128 
     | 
    
         
             
            ```ruby
         
     | 
| 
       125 
129 
     | 
    
         
             
            class SqlUserRepository
         
     | 
| 
       126 
     | 
    
         
            -
              include  
     | 
| 
      
 130 
     | 
    
         
            +
              include Sql
         
     | 
| 
       127 
131 
     | 
    
         | 
| 
       128 
132 
     | 
    
         
             
              class << self
         
     | 
| 
       129 
133 
     | 
    
         
             
                def random
         
     | 
| 
         @@ -159,7 +163,7 @@ programmatically resolve a dependency from the container. 
     | 
|
| 
       159 
163 
     | 
    
         | 
| 
       160 
164 
     | 
    
         
             
            ### Testing
         
     | 
| 
       161 
165 
     | 
    
         | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
      
 166 
     | 
    
         
            +
            When testing you may want to mock how the dependences are resolved.
         
     | 
| 
       163 
167 
     | 
    
         | 
| 
       164 
168 
     | 
    
         
             
            In this example we mock the Users repository call to return a reliable set of
         
     | 
| 
       165 
169 
     | 
    
         
             
            data for testing.
         
     | 
| 
         @@ -200,3 +204,24 @@ is then unmocked (returned back to it's original state) 
     | 
|
| 
       200 
204 
     | 
    
         
             
            ## Licence
         
     | 
| 
       201 
205 
     | 
    
         | 
| 
       202 
206 
     | 
    
         
             
            See `LICENCE` file.
         
     | 
| 
      
 207 
     | 
    
         
            +
             
     | 
| 
      
 208 
     | 
    
         
            +
            ## Development
         
     | 
| 
      
 209 
     | 
    
         
            +
             
     | 
| 
      
 210 
     | 
    
         
            +
            ### Prerequisites
         
     | 
| 
      
 211 
     | 
    
         
            +
             
     | 
| 
      
 212 
     | 
    
         
            +
            * Docker Community Edition - https://www.docker.com/community-edition
         
     | 
| 
      
 213 
     | 
    
         
            +
            * Docker Compose - https://docs.docker.com/compose/
         
     | 
| 
      
 214 
     | 
    
         
            +
            * Make - https://www.gnu.org/software/make/
         
     | 
| 
      
 215 
     | 
    
         
            +
             
     | 
| 
      
 216 
     | 
    
         
            +
            ### Setup
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
            * `make` will build the application ready for use.
         
     | 
| 
      
 219 
     | 
    
         
            +
             
     | 
| 
      
 220 
     | 
    
         
            +
            ### Lint
         
     | 
| 
      
 221 
     | 
    
         
            +
             
     | 
| 
      
 222 
     | 
    
         
            +
            * `make lint` will run linting
         
     | 
| 
      
 223 
     | 
    
         
            +
             
     | 
| 
      
 224 
     | 
    
         
            +
            ### Tests
         
     | 
| 
      
 225 
     | 
    
         
            +
             
     | 
| 
      
 226 
     | 
    
         
            +
            * `make spec` will run tests
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
    
        data/lib/yep/version.rb
    CHANGED
    
    
    
        data/test/test_yep.rb
    CHANGED
    
    
    
        data/yep.gemspec
    CHANGED
    
    | 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            $LOAD_PATH.push File.expand_path('lib', __dir__)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require 'yep/version'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
         @@ -16,4 +17,5 @@ Gem::Specification.new do |s| 
     | 
|
| 
       16 
17 
     | 
    
         
             
              s.executables   = `git ls-files -- bin/*`
         
     | 
| 
       17 
18 
     | 
    
         
             
                .split("\n").map { |f| File.basename(f) }
         
     | 
| 
       18 
19 
     | 
    
         
             
              s.require_paths = ['lib']
         
     | 
| 
      
 20 
     | 
    
         
            +
              s.required_ruby_version = '> 3.0'
         
     | 
| 
       19 
21 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: yep
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version:  
     | 
| 
      
 4 
     | 
    
         
            +
              version: 3.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Dan Watson
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-11-10 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            email:
         
     | 
| 
         @@ -39,16 +39,16 @@ require_paths: 
     | 
|
| 
       39 
39 
     | 
    
         
             
            - lib
         
     | 
| 
       40 
40 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       41 
41 
     | 
    
         
             
              requirements:
         
     | 
| 
       42 
     | 
    
         
            -
              - - " 
     | 
| 
      
 42 
     | 
    
         
            +
              - - ">"
         
     | 
| 
       43 
43 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       44 
     | 
    
         
            -
                  version: '0'
         
     | 
| 
      
 44 
     | 
    
         
            +
                  version: '3.0'
         
     | 
| 
       45 
45 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       46 
46 
     | 
    
         
             
              requirements:
         
     | 
| 
       47 
47 
     | 
    
         
             
              - - ">="
         
     | 
| 
       48 
48 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       49 
49 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       50 
50 
     | 
    
         
             
            requirements: []
         
     | 
| 
       51 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 51 
     | 
    
         
            +
            rubygems_version: 3.2.22
         
     | 
| 
       52 
52 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       53 
53 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       54 
54 
     | 
    
         
             
            summary: Yep is a dependency injection framework written in ruby
         
     |