planter 0.1.3 → 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
  SHA256:
3
- metadata.gz: a542b8919dda44137996b078e0ac3f773fc8b85bed2225193de3f2a36bdfe099
4
- data.tar.gz: '058271874209001fd8de03630c2e3f162959621769225bb354060f1ed8848354'
3
+ metadata.gz: 85e12676f9e3c992f26939f709bb8ff9785a75cfbf13a5279075e2e84ae2adc9
4
+ data.tar.gz: 130e7dd566d20b09dcfb38c4d62c76d872b169b459f68eff0a2d8715c13f320a
5
5
  SHA512:
6
- metadata.gz: c9728b99a23877a7f96f4267b963dd7f4e15f4c385303759476937f7f3f33bd6335ec0e6b89fde733ecfd7f5380386ba86ca26bfbdb9ac70f587b8a05efc8812
7
- data.tar.gz: 1af8f9af55ca77f91f2ef7c01b8cb2c1919166be12f8785d779137d68237050b1ab259726da9546dea7dd2184f85431930e9ec8785d269c16ee1ba6add884b92
6
+ metadata.gz: 535f7b4909895f4f2ed6219919cbd620b3f283daecd693457ce52dfa7ec3d8281d49d7487dc530ced549a52d55719759e3f0975efa833763475fe03a1b863171
7
+ data.tar.gz: 36df7d4e59476de2f1526b66e1571d70221ff77204eac23e2d16408ddf7ca6bfcdacbfb351e0a9f4323ca2439c407afb5ecbd3a88725493d62ef8c0ac594f1f4
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # Planter
2
2
  [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fevanthegrayt%2Fplanter%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/evanthegrayt/planter/goto?ref=master)
3
3
  [![Gem Version](https://badge.fury.io/rb/planter.svg)](https://badge.fury.io/rb/planter)
4
+ ![Language: Ruby](https://img.shields.io/static/v1?label=language&message=Ruby&color=CC342D&style=flat&logo=ruby&logoColor=CC342D)
4
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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.1.3'
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 %>,"Test User1"
154
- <%= Participant.find_by(email: 'test2@example.com').id %>,"Test User2"
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
  ```
@@ -15,19 +15,21 @@ module Planter
15
15
  # Minor version.
16
16
  #
17
17
  # @return [Integer]
18
- MINOR = 1
18
+ MINOR = 2
19
19
 
20
20
  ##
21
21
  # Patch version.
22
22
  #
23
23
  # @return [Integer]
24
- PATCH = 3
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 self.to_a
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 self.to_s
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 self.to_h
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 self.config
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 self.reset_config
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 self.configure
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 self.seed
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.1.3
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-01-05 00:00:00.000000000 Z
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: 6.1.4.4
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: 6.1.4.4
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.22
69
+ rubygems_version: 3.2.33
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Framework for seeding rails applications.