planter 0.1.3 → 0.2.0
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/README.md +17 -7
 - data/lib/planter/version.rb +7 -5
 - data/lib/planter.rb +6 -4
 - 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: 85e12676f9e3c992f26939f709bb8ff9785a75cfbf13a5279075e2e84ae2adc9
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 130e7dd566d20b09dcfb38c4d62c76d872b169b459f68eff0a2d8715c13f320a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 535f7b4909895f4f2ed6219919cbd620b3f283daecd693457ce52dfa7ec3d8281d49d7487dc530ced549a52d55719759e3f0975efa833763475fe03a1b863171
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 36df7d4e59476de2f1526b66e1571d70221ff77204eac23e2d16408ddf7ca6bfcdacbfb351e0a9f4323ca2439c407afb5ecbd3a88725493d62ef8c0ac594f1f4
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,10 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Planter
         
     | 
| 
       2 
2 
     | 
    
         
             
            [](https://actions-badge.atrox.dev/evanthegrayt/planter/goto?ref=master)
         
     | 
| 
       3 
3 
     | 
    
         
             
            [](https://badge.fury.io/rb/planter)
         
     | 
| 
      
 4 
     | 
    
         
            +
            
         
     | 
| 
       4 
5 
     | 
    
         
             
            [](https://opensource.org/licenses/MIT)
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            > Pre-release version! Anything is subject to change in the near future!
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
7 
     | 
    
         
             
            Seeds for Rails applications can get complicated fast, and Rails doesn't provide
         
     | 
| 
       9 
8 
     | 
    
         
             
            much for assisting with this process. This plugin seeks to rectify that by
         
     | 
| 
       10 
9 
     | 
    
         
             
            providing easy ways to seed specific tables.
         
     | 
| 
         @@ -24,7 +23,7 @@ currently a pre-release version, it's recommended to lock it to a specific 
     | 
|
| 
       24 
23 
     | 
    
         
             
            version, as breaking changes may occur, even at the minor level.
         
     | 
| 
       25 
24 
     | 
    
         | 
| 
       26 
25 
     | 
    
         
             
            ```ruby
         
     | 
| 
       27 
     | 
    
         
            -
            gem 'planter', '0. 
     | 
| 
      
 26 
     | 
    
         
            +
            gem 'planter', '0.2.0'
         
     | 
| 
       28 
27 
     | 
    
         
             
            ```
         
     | 
| 
       29 
28 
     | 
    
         | 
| 
       30 
29 
     | 
    
         
             
            And then execute:
         
     | 
| 
         @@ -146,12 +145,23 @@ end 
     | 
|
| 
       146 
145 
     | 
    
         
             
            ```
         
     | 
| 
       147 
146 
     | 
    
         | 
| 
       148 
147 
     | 
    
         
             
            `ERB` can be used in the CSV files if you end the file name with `.csv.erb` or
         
     | 
| 
       149 
     | 
    
         
            -
            `.erb.csv`. For example, `users.csv.erb`.
         
     | 
| 
      
 148 
     | 
    
         
            +
            `.erb.csv`. For example, `users.csv.erb`. When using ERB, instance variables set
         
     | 
| 
      
 149 
     | 
    
         
            +
            in the seeder can be used in the CSV.
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 152 
     | 
    
         
            +
            class UsersSeeder < Planter::Seeder
         
     | 
| 
      
 153 
     | 
    
         
            +
              seeding_method :csv, csv_name: :people
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
              def initialize
         
     | 
| 
      
 156 
     | 
    
         
            +
                @name_prefix = 'Test User'
         
     | 
| 
      
 157 
     | 
    
         
            +
              end
         
     | 
| 
      
 158 
     | 
    
         
            +
            end
         
     | 
| 
      
 159 
     | 
    
         
            +
            ```
         
     | 
| 
       150 
160 
     | 
    
         | 
| 
       151 
161 
     | 
    
         
             
            ```
         
     | 
| 
       152 
162 
     | 
    
         
             
            participant_id,name
         
     | 
| 
       153 
     | 
    
         
            -
            <%= Participant.find_by(email: 'test1@example.com').id  
     | 
| 
       154 
     | 
    
         
            -
            <%= Participant.find_by(email: 'test2@example.com').id  
     | 
| 
      
 163 
     | 
    
         
            +
            <%= Participant.find_by(email: 'test1@example.com').id %>,<%= @name_prefix %> 1
         
     | 
| 
      
 164 
     | 
    
         
            +
            <%= Participant.find_by(email: 'test2@example.com').id %>,<%= @name_prefix %> 2
         
     | 
| 
       155 
165 
     | 
    
         
             
            ```
         
     | 
| 
       156 
166 
     | 
    
         | 
| 
       157 
167 
     | 
    
         
             
            Note that, if you need to change the trim mode for ERB, you can set a default in
         
     | 
| 
         @@ -277,7 +287,7 @@ class UsersSeeder < Planter::Seeder 
     | 
|
| 
       277 
287 
     | 
    
         
             
              }
         
     | 
| 
       278 
288 
     | 
    
         | 
| 
       279 
289 
     | 
    
         
             
              def seed
         
     | 
| 
       280 
     | 
    
         
            -
                USERS.each { |email, attrs| User.where(email).first_or_create!(attrs) }
         
     | 
| 
      
 290 
     | 
    
         
            +
                USERS.each { |email, attrs| User.where(email: email).first_or_create!(attrs) }
         
     | 
| 
       281 
291 
     | 
    
         
             
              end
         
     | 
| 
       282 
292 
     | 
    
         
             
            end
         
     | 
| 
       283 
293 
     | 
    
         
             
            ```
         
     | 
    
        data/lib/planter/version.rb
    CHANGED
    
    | 
         @@ -15,19 +15,21 @@ module Planter 
     | 
|
| 
       15 
15 
     | 
    
         
             
                # Minor version.
         
     | 
| 
       16 
16 
     | 
    
         
             
                #
         
     | 
| 
       17 
17 
     | 
    
         
             
                # @return [Integer]
         
     | 
| 
       18 
     | 
    
         
            -
                MINOR =  
     | 
| 
      
 18 
     | 
    
         
            +
                MINOR = 2
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                ##
         
     | 
| 
       21 
21 
     | 
    
         
             
                # Patch version.
         
     | 
| 
       22 
22 
     | 
    
         
             
                #
         
     | 
| 
       23 
23 
     | 
    
         
             
                # @return [Integer]
         
     | 
| 
       24 
     | 
    
         
            -
                PATCH =  
     | 
| 
      
 24 
     | 
    
         
            +
                PATCH = 0
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                module_function
         
     | 
| 
       25 
27 
     | 
    
         | 
| 
       26 
28 
     | 
    
         
             
                ##
         
     | 
| 
       27 
29 
     | 
    
         
             
                # Version as +[MAJOR, MINOR, PATCH]+
         
     | 
| 
       28 
30 
     | 
    
         
             
                #
         
     | 
| 
       29 
31 
     | 
    
         
             
                # @return [Array]
         
     | 
| 
       30 
     | 
    
         
            -
                def  
     | 
| 
      
 32 
     | 
    
         
            +
                def to_a
         
     | 
| 
       31 
33 
     | 
    
         
             
                  [MAJOR, MINOR, PATCH]
         
     | 
| 
       32 
34 
     | 
    
         
             
                end
         
     | 
| 
       33 
35 
     | 
    
         | 
| 
         @@ -35,7 +37,7 @@ module Planter 
     | 
|
| 
       35 
37 
     | 
    
         
             
                # Version as +MAJOR.MINOR.PATCH+
         
     | 
| 
       36 
38 
     | 
    
         
             
                #
         
     | 
| 
       37 
39 
     | 
    
         
             
                # @return [String]
         
     | 
| 
       38 
     | 
    
         
            -
                def  
     | 
| 
      
 40 
     | 
    
         
            +
                def to_s
         
     | 
| 
       39 
41 
     | 
    
         
             
                  to_a.join('.')
         
     | 
| 
       40 
42 
     | 
    
         
             
                end
         
     | 
| 
       41 
43 
     | 
    
         | 
| 
         @@ -43,7 +45,7 @@ module Planter 
     | 
|
| 
       43 
45 
     | 
    
         
             
                # Version as +{major: MAJOR, minor: MINOR, patch: PATCH}+
         
     | 
| 
       44 
46 
     | 
    
         
             
                #
         
     | 
| 
       45 
47 
     | 
    
         
             
                # @return [Hash]
         
     | 
| 
       46 
     | 
    
         
            -
                def  
     | 
| 
      
 48 
     | 
    
         
            +
                def to_h
         
     | 
| 
       47 
49 
     | 
    
         
             
                  Hash[%i[major minor patch].zip(to_a)]
         
     | 
| 
       48 
50 
     | 
    
         
             
                end
         
     | 
| 
       49 
51 
     | 
    
         
             
              end
         
     | 
    
        data/lib/planter.rb
    CHANGED
    
    | 
         @@ -24,11 +24,13 @@ require 'planter/seeder' 
     | 
|
| 
       24 
24 
     | 
    
         
             
            #
         
     | 
| 
       25 
25 
     | 
    
         
             
            #   Planter.seed
         
     | 
| 
       26 
26 
     | 
    
         
             
            module Planter
         
     | 
| 
      
 27 
     | 
    
         
            +
              module_function
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       27 
29 
     | 
    
         
             
              ##
         
     | 
| 
       28 
30 
     | 
    
         
             
              # The seeder configuration.
         
     | 
| 
       29 
31 
     | 
    
         
             
              #
         
     | 
| 
       30 
32 
     | 
    
         
             
              # @return [Planter::Config]
         
     | 
| 
       31 
     | 
    
         
            -
              def  
     | 
| 
      
 33 
     | 
    
         
            +
              def config
         
     | 
| 
       32 
34 
     | 
    
         
             
                @config ||= Planter::Config.new
         
     | 
| 
       33 
35 
     | 
    
         
             
              end
         
     | 
| 
       34 
36 
     | 
    
         | 
| 
         @@ -36,7 +38,7 @@ module Planter 
     | 
|
| 
       36 
38 
     | 
    
         
             
              # Resets the config back to its initial state.
         
     | 
| 
       37 
39 
     | 
    
         
             
              #
         
     | 
| 
       38 
40 
     | 
    
         
             
              # @return [Planter::Config]
         
     | 
| 
       39 
     | 
    
         
            -
              def  
     | 
| 
      
 41 
     | 
    
         
            +
              def reset_config
         
     | 
| 
       40 
42 
     | 
    
         
             
                @config = Planter::Config.new
         
     | 
| 
       41 
43 
     | 
    
         
             
              end
         
     | 
| 
       42 
44 
     | 
    
         | 
| 
         @@ -52,7 +54,7 @@ module Planter 
     | 
|
| 
       52 
54 
     | 
    
         
             
              #     config.seeders_directory = 'db/seeds'
         
     | 
| 
       53 
55 
     | 
    
         
             
              #     config.csv_files_directory = 'db/seed_files'
         
     | 
| 
       54 
56 
     | 
    
         
             
              #   end
         
     | 
| 
       55 
     | 
    
         
            -
              def  
     | 
| 
      
 57 
     | 
    
         
            +
              def configure
         
     | 
| 
       56 
58 
     | 
    
         
             
                config.tap { |c| yield c }
         
     | 
| 
       57 
59 
     | 
    
         
             
              end
         
     | 
| 
       58 
60 
     | 
    
         | 
| 
         @@ -65,7 +67,7 @@ module Planter 
     | 
|
| 
       65 
67 
     | 
    
         
             
              # @example
         
     | 
| 
       66 
68 
     | 
    
         
             
              #   # db/seeds.rb, assuming your +configure+ block is in an initializer.
         
     | 
| 
       67 
69 
     | 
    
         
             
              #   Planter.seed
         
     | 
| 
       68 
     | 
    
         
            -
              def  
     | 
| 
      
 70 
     | 
    
         
            +
              def seed
         
     | 
| 
       69 
71 
     | 
    
         
             
                seeders = ENV['SEEDERS']&.split(',') || config.seeders&.map(&:to_s)
         
     | 
| 
       70 
72 
     | 
    
         
             
                raise RuntimeError, 'No seeders specified' if seeders.blank?
         
     | 
| 
       71 
73 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: planter
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Evan Gray
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2022- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2022-05-02 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -16,14 +16,14 @@ dependencies: 
     | 
|
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
17 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
     | 
    
         
            -
                    version:  
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 7.0.2.3
         
     | 
| 
       20 
20 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       21 
21 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
22 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
23 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
24 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
     | 
    
         
            -
                    version:  
     | 
| 
      
 26 
     | 
    
         
            +
                    version: 7.0.2.3
         
     | 
| 
       27 
27 
     | 
    
         
             
            description: Create a seeder for each table in your database, and easily seed from
         
     | 
| 
       28 
28 
     | 
    
         
             
              CSV or custom methods
         
     | 
| 
       29 
29 
     | 
    
         
             
            email:
         
     | 
| 
         @@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       66 
66 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       67 
67 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       68 
68 
     | 
    
         
             
            requirements: []
         
     | 
| 
       69 
     | 
    
         
            -
            rubygems_version: 3.2. 
     | 
| 
      
 69 
     | 
    
         
            +
            rubygems_version: 3.2.33
         
     | 
| 
       70 
70 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       71 
71 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       72 
72 
     | 
    
         
             
            summary: Framework for seeding rails applications.
         
     |