seedify 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -1
- data/lib/seedify.rb +1 -0
- data/lib/seedify/base.rb +1 -0
- data/lib/seedify/call_stack.rb +9 -1
- data/lib/seedify/callbacks.rb +41 -0
- data/lib/seedify/param_reader.rb +2 -0
- data/lib/seedify/version.rb +1 -1
- data/lib/tasks/seedify.rake +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 966953a8b2503201652c70f8eec6ad1138602ef3
|
4
|
+
data.tar.gz: ccb99890b1f877f49550266a780f0b4b22558680
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 091a2840a37eec2966cf5b848a39f2009cf9824c3637cc8442fe153b14b7c6b32ef0dc1002284c45c05369572ff642d58cb89f8b856766e5ad1c1315cbc2a2fd
|
7
|
+
data.tar.gz: 9b497bbe567544ca8038ab4d2b25981fa8f0dd2de99305806da3a49eabe09e62977858a272c10094c136aa889ca67a1d2276e43d9eb426eaa028867121dbbdc5
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Here's an overview of what you can achieve with **seedify**:
|
|
12
12
|
|
13
13
|
- organize seed code in object-oriented, Rails convention fitting fashion
|
14
14
|
- take advantage of inheritance and modularization when writing seeds
|
15
|
-
- invoke seeds as rake tasks or from within the
|
15
|
+
- invoke seeds as rake tasks or from within the app/console
|
16
16
|
- allow to specify custom parameters for your seeds, typed and with defaults
|
17
17
|
- log the seed progress (e.g. mass creation) without effort
|
18
18
|
- combine with [factory_girl](https://github.com/thoughtbot/factory_girl) to simplify object creation and share fixtures with specs
|
@@ -274,6 +274,38 @@ UserSeed.call user_prefix: 'user_generated_by_app_seed'
|
|
274
274
|
|
275
275
|
This way, within **UserSeed**, the `user_prefix` param will equal to *user_generated_by_app_seed* regardless of the one specified when calling the application seed from console or command-line.
|
276
276
|
|
277
|
+
### Callbacks and multi-tenancy
|
278
|
+
|
279
|
+
If you have code that needs to be run before whole seed suite (similar to `before(:all)` in RSpec), you can use the `before_all` method. It'll be called just once - the first time seed using it or its descendants will be called. Common use case is to pre-set proper schema with multi-tenant application using the [apartment](https://github.com/influitive/apartment) gem:
|
280
|
+
|
281
|
+
```ruby
|
282
|
+
class TenantSeed < Seedify::Base
|
283
|
+
param_reader :tenant
|
284
|
+
|
285
|
+
before_all :switch_tenant
|
286
|
+
|
287
|
+
def call
|
288
|
+
SomeSeed.call
|
289
|
+
OtherSeed.call
|
290
|
+
end
|
291
|
+
|
292
|
+
protected
|
293
|
+
|
294
|
+
def switch_tenant
|
295
|
+
log "switching to *#{tenant}* schema"
|
296
|
+
Apartment::Tenant.switch!(tenant)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
class SomeSeed < TenantSeed
|
301
|
+
end
|
302
|
+
|
303
|
+
class OtherSeed < TenantSeed
|
304
|
+
end
|
305
|
+
```
|
306
|
+
|
307
|
+
You can still call tenant seed or some/other seeds separately and proper schema will always be picked.
|
308
|
+
|
277
309
|
## Configuration
|
278
310
|
|
279
311
|
You can override the default `db/seeds` seed directory if you want to place your seed objects in different place in the project:
|
data/lib/seedify.rb
CHANGED
data/lib/seedify/base.rb
CHANGED
data/lib/seedify/call_stack.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Seedify
|
2
|
+
module Callbacks
|
3
|
+
TYPES = %w{before_all}
|
4
|
+
|
5
|
+
def self.with_callbacks(proc)
|
6
|
+
@finished_before_all ||= []
|
7
|
+
|
8
|
+
proc.class.get_callbacks(:before_all).each do |callback|
|
9
|
+
unless @finished_before_all.include?(callback)
|
10
|
+
@finished_before_all << callback
|
11
|
+
|
12
|
+
proc.send(callback)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
|
19
|
+
def inherited(subclass)
|
20
|
+
super
|
21
|
+
|
22
|
+
TYPES.each do |type|
|
23
|
+
get_callbacks(type).each do |callback|
|
24
|
+
subclass.send(type, callback)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
TYPES.each do |type|
|
30
|
+
define_method type do |callback|
|
31
|
+
@callbacks ||= {}
|
32
|
+
@callbacks[type] ||= []
|
33
|
+
@callbacks[type] << callback
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_callbacks(type)
|
38
|
+
Array((@callbacks || {})[type.to_s])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/seedify/param_reader.rb
CHANGED
data/lib/seedify/version.rb
CHANGED
data/lib/tasks/seedify.rake
CHANGED
@@ -14,7 +14,7 @@ namespace :seedify do
|
|
14
14
|
next if seed == 'ApplicationSeed'
|
15
15
|
|
16
16
|
desc "Call the #{seed.underscore.humanize}"
|
17
|
-
task seed.underscore.gsub('/', ':').sub(/_seed$/, '') => :environment do
|
17
|
+
task seed.underscore.gsub('/', ':').sub(/_seed$/, '').sub(/:base$/, '') => :environment do
|
18
18
|
seed.constantize.call(task: true)
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seedify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol Słuszniak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/seedify.rb
|
137
137
|
- lib/seedify/base.rb
|
138
138
|
- lib/seedify/call_stack.rb
|
139
|
+
- lib/seedify/callbacks.rb
|
139
140
|
- lib/seedify/logger.rb
|
140
141
|
- lib/seedify/param_reader.rb
|
141
142
|
- lib/seedify/param_value.rb
|