the_gardener 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db79ab3a29e3cbefe4357b3964b5615576e8342f
4
+ data.tar.gz: c3db4504dba4334a1748241a4c3ca344efd24bc9
5
+ SHA512:
6
+ metadata.gz: 90f68fdad0f70b4dbafd04f48ff2ab630b6cd5fc44ef9d8069af9e8882929a86df0c135b7db590bfd68eb67493f5ed8cada72db10dad6f44c6b1c5239b5c656d
7
+ data.tar.gz: 1c30d0d2a3281a784986f19f4b62470b31edec6b957d3867b60f52989fbb24f792f5e4fd5c861cf3519c119d15a913acdf0a89ba3eaf0e2d121edcfa4ed0ebd7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in the_gardener.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Robert Starke (robertst81 (at) gmail com )
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # TheGardener
2
+
3
+ TheGardener helps you to versionize your seed files. If you need to separate
4
+ seedings, this gem could be helpfull for you.
5
+
6
+ TheGardener generates seed files filed under `db/seeds` and stores which seed
7
+ allready be done. it's the same procedure like migrations.
8
+
9
+
10
+ ## Installation
11
+
12
+ hm, yeah. just add this to your Gemfile:
13
+
14
+ ```ruby
15
+ gem 'the_gardener'
16
+ ```
17
+
18
+ And then execute:
19
+ ```
20
+ $ bundle
21
+ ```
22
+ Or install it yourself as:
23
+ ```
24
+ $ gem install the_gardener
25
+ ```
26
+
27
+ Now you just have to install the_gardener in your project:
28
+ ```
29
+ rails g the_gardener:install
30
+ ```
31
+
32
+ and run your migrations.
33
+
34
+ ## Usage
35
+
36
+ Ok, to create a seed file just run:
37
+
38
+ ```
39
+ rails g seed your_filename_for_your_seed
40
+ ```
41
+
42
+ After this, you can put your code to the seedfile (filed under db/seeds).
43
+ Just put some `Model.create` stuff there.
44
+
45
+ to run all your seed files just
46
+
47
+ ```
48
+ rake tg:seed
49
+ ```
50
+
51
+ If there is some seed which throws an error, the task stopped and all seeds in
52
+ this seedfile will be canceled
53
+
54
+ ## The MIT License (MIT)
55
+
56
+ Copyright (c) 2015 [Robert Starke](robertst81+github@gmail.com)
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining a copy
59
+ of this software and associated documentation files (the "Software"), to deal
60
+ in the Software without restriction, including without limitation the rights
61
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
62
+ copies of the Software, and to permit persons to whom the Software is
63
+ furnished to do so, subject to the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be included in
66
+ all copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
69
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
70
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
71
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
72
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
73
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
74
+ THE SOFTWARE.
75
+
76
+ ## Questions?
77
+
78
+ If you have further questions, code smells, hints or a beer, just contact me :)
79
+
80
+ ## Contributing
81
+
82
+ 1. Fork it ( https://github.com/robst/the_gardener/fork )
83
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
84
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
85
+ 4. Push to the branch (`git push origin my-new-feature`)
86
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "the_gardener"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ require 'rails/generators/base'
2
+
3
+ class SeedGenerator < Rails::Generators::NamedBase
4
+ desc "Generates a seedfile filed under db/seeds with current timestamp and
5
+ your given name"
6
+ def create_seed_file
7
+ create_file filename
8
+ puts "\tnow you can put your seeds into #{filename}"
9
+ end
10
+
11
+ def filename
12
+ @filename ||= "db/seeds/#{DateTime.current.to_s(:number)}_#{file_name.to_s.underscore}.rb"
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module TheGardener
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ desc "add the_gardener migrations to your db/migrate directory"
9
+
10
+ def self.next_migration_number(path)
11
+ unless @prev_migration_nr
12
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
13
+ else
14
+ @prev_migration_nr += 1
15
+ end
16
+ @prev_migration_nr.to_s
17
+ end
18
+
19
+ def copy_migrations
20
+ migration_template "create_the_gardener_seed_migrations.rb", "db/migrate/create_the_gardener_seed_migrations.rb"
21
+ puts "done.\nnow you have to run the db:migrate task to update your database"
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ class CreateTheGardenerSeedMigrations < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :seed_migrations do |t|
4
+ t.string :version
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :seed_migrations
10
+ end
11
+ end
data/lib/tasks/tg.rake ADDED
@@ -0,0 +1,24 @@
1
+ namespace :tg do
2
+ desc "load the seeds filed under db/seeds"
3
+ task :seed => :environment do
4
+ seed_directory = File.join('db','seeds')
5
+ Dir.open(seed_directory).sort.each do |seed_file|
6
+ if File.file? File.join(seed_directory,seed_file)
7
+ unless TheGardener::versioned? TheGardener::filename_version(seed_file)
8
+ puts "loading seed: #{seed_file}"
9
+ begin
10
+ ActiveRecord::Base.transaction do
11
+ load File.join(seed_directory,seed_file)
12
+ TheGardener::versionize TheGardener::filename_version(seed_file)
13
+ end
14
+ rescue => e
15
+ puts "#{'-'*30}\nError on: #{File.join(seed_directory,seed_file)}"
16
+ puts "message: #{e.message}\n#{'-'*30}"
17
+ puts "seeding stopped"
18
+ raise ActiveRecord::Rollback
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module TheGardener
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ require "the_gardener/version"
2
+
3
+ module TheGardener
4
+ if defined?(Rails)
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :the_gardener
7
+
8
+ rake_tasks do
9
+ load "tasks/tg.rake"
10
+ end
11
+ end
12
+ end
13
+ class SeedMigration < ActiveRecord::Base
14
+ end
15
+
16
+ def self.versioned? version
17
+ SeedMigration.where('version=?', version).any?
18
+ end
19
+
20
+ def self.versionize version
21
+ SeedMigration.create(version: version)
22
+ end
23
+
24
+ def self.filename_version filename
25
+ filename.split('_').first
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'the_gardener/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "the_gardener"
8
+ spec.version = TheGardener::VERSION
9
+ spec.authors = ["Robert Starke"]
10
+ spec.email = ["robertst81@gmail.com"]
11
+
12
+
13
+ spec.summary = "Gardener, take's care about your seeds!"
14
+ spec.description = "A Gem for versioned seed files. Create seed files and use
15
+ it like the active record migrations. it has an generator
16
+ for seeds, and a task to load all seeds. look at the
17
+ github page for more information."
18
+
19
+
20
+ spec.homepage = "https://github.com/robst/the_gardener"
21
+ spec.license = "MIT"
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.8"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency 'rails', '>= 3.2.0'
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_gardener
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Starke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ description: "A Gem for versioned seed files. Create seed files and use\n it
56
+ like the active record migrations. it has an generator \n for
57
+ seeds, and a task to load all seeds. look at the \n github
58
+ page for more information."
59
+ email:
60
+ - robertst81@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/generators/seed_generator.rb
74
+ - lib/generators/the_gardener/install/install_generator.rb
75
+ - lib/generators/the_gardener/install/templates/create_the_gardener_seed_migrations.rb
76
+ - lib/tasks/tg.rake
77
+ - lib/the_gardener.rb
78
+ - lib/the_gardener/version.rb
79
+ - the_gardener.gemspec
80
+ homepage: https://github.com/robst/the_gardener
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.6
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Gardener, take's care about your seeds!
104
+ test_files: []