cuttings 0.1.0 → 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
  SHA1:
3
- metadata.gz: 2691d8ba7417ac94552395c47e1a6d0ea792f6a0
4
- data.tar.gz: 4c414ee4662e7e642be45e51c980f2c992ee1baf
3
+ metadata.gz: c9867e735e11f82a4e79dbfb8d2d809d43ecee9f
4
+ data.tar.gz: 2914a5a0cbb9da373fba49d58c7b55e261065085
5
5
  SHA512:
6
- metadata.gz: 6b34dda19039bfdaca352ae125dede3391f3dc60e56f13cb58adbc5184b6a004f751591568f4a8307596e3426238e854e4b80ae62caf3d1d3d49b5a72ae2d2e2
7
- data.tar.gz: df1ed76b541300f76f630081f63143c5446f1fea4f6b8dbe2b1b1536ffac26b48c1f7be309abc225992685d0384e16cba67f19ebfa9e3f68e607ff6cfe8c4e38
6
+ metadata.gz: f010cc3512589b10722c0a084fae99e288f0404d904e7e29bab0385bc3bc8deb62833928f8a2ebc1013176c72c56b113af699fd4dfa43a4479fbc3cf43d83329
7
+ data.tar.gz: e319680b8d7f0743e1eff0bfaab831aad03a2b4b431a0b4d4ab6ead9ee4f59f80c9bd4818b17e49c4e059e8048d97b5b0b39690c368f26bb1771487e2bf1ee8d
data/README.md CHANGED
@@ -13,22 +13,60 @@ Add to your Gemfile and `bundle install` :
13
13
  gem 'cuttings'
14
14
  ```
15
15
 
16
+ Then create the directory structure with the install generator :
17
+
18
+ ```bash
19
+ rails generate cuttings:install
20
+ ```
21
+
16
22
  ## Usage
17
23
 
18
- In your `db/seeds.rb` or in a `rake` task :
24
+ Your can use **Cuttings** in your `db/seeds.rb` file, or inside `rake` tasks,
25
+ depending on which method you prefer.
26
+
27
+ If you choose the `db/seeds.rb` file way, just use the API as explained in the
28
+ **DSL** section.
29
+
30
+ If you choose the `rake` task way, a generator is provided to help you organize
31
+ your seed tasks.
32
+
33
+ ### Using the `cuttings` generator :
34
+
35
+ But a generator is provided to help you create separated seed data accessible
36
+ with `rake` tasks.
37
+
38
+ ```bash
39
+ rails generate cuttings users
40
+ ```
41
+
42
+ Which will generate the following file in `lib/seeds/tasks/users.rake`
19
43
 
20
44
  ```ruby
21
- require 'cuttings'
45
+ namespace :seed do
46
+ task users: :environment do
47
+ Cuttings.plant do
48
+ # Add your seeding code here
49
+ end
50
+ end
51
+ end
52
+ ```
22
53
 
23
- Cuttings.plant do
24
- truncate %w(Visit)
54
+ ### Example usage
25
55
 
26
- seed 'User' do
27
- create(
28
- name: 'Jean Jean',
29
- email: 'jean@jean.com',
30
- avatar: attachment('user.png')
31
- )
56
+ ```ruby
57
+ namespace :seed do
58
+ task users: :environment do
59
+ Cuttings.plant do
60
+ truncate %w(Visit)
61
+
62
+ seed 'User' do
63
+ create(
64
+ name: 'Jean Jean',
65
+ email: 'jean@jean.com',
66
+ avatar: attachment('user.png')
67
+ )
68
+ end
69
+ end
32
70
  end
33
71
  end
34
72
  ```
data/lib/cuttings.rb CHANGED
@@ -10,3 +10,5 @@ module Cuttings
10
10
  greenhouse.process
11
11
  end
12
12
  end
13
+
14
+ require 'cuttings/railtie' if defined?(Rails)
@@ -0,0 +1,11 @@
1
+ module Cuttings
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ tasks_path = Rails.root.join('lib', 'seeds', 'tasks', '**', '*.rake')
5
+
6
+ Dir[tasks_path].each do |file|
7
+ load file
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Cuttings
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,21 @@
1
+ require 'fileutils'
2
+
3
+ class CuttingsGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc 'Cuttings install generator'
7
+
8
+ def welcome
9
+ say 'Creating new cuttings ...'
10
+ end
11
+
12
+ def create_folders
13
+ template 'cuttings.rake', "lib/seeds/tasks/#{ name }.rake"
14
+ end
15
+
16
+ private
17
+
18
+ def base_dir
19
+ @base_dir ||= Rails.root.join('lib', 'seeds')
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ require 'fileutils'
2
+
3
+ module Cuttings
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ desc 'Cuttings install generator'
8
+
9
+ def welcome
10
+ say 'Installing cuttings ...'
11
+ end
12
+
13
+ def create_folders
14
+ FileUtils.mkdir_p(base_dir.join('attachments'))
15
+ FileUtils.mkdir_p(base_dir.join('tasks'))
16
+ end
17
+
18
+ private
19
+
20
+ def base_dir
21
+ @base_dir ||= Rails.root.join('lib', 'seeds')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ namespace :seed do
2
+ task <%= name %>: :environment do
3
+ Cuttings.plant do
4
+ # Add your seeding code here
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuttings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
@@ -51,7 +51,11 @@ files:
51
51
  - lib/cuttings.rb
52
52
  - lib/cuttings/cutting.rb
53
53
  - lib/cuttings/greenhouse.rb
54
+ - lib/cuttings/railtie.rb
54
55
  - lib/cuttings/version.rb
56
+ - lib/generators/cuttings/cuttings_generator.rb
57
+ - lib/generators/cuttings/install/install_generator.rb
58
+ - lib/generators/cuttings/templates/cuttings.rake
55
59
  - lib/tasks/cuttings_tasks.rake
56
60
  homepage: http://github.com/glyph-fr/cuttings
57
61
  licenses: