seeding 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seedy.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Nikolai Manek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # Seeding
2
+
3
+ Seeding is a seed.rb generator for lazy and/or smart people. I had to create seed files for all sorts of projects but in most cases I had to create them based on conditions etc. Like "Hey, can you create a seed.rb which includes all customers which are marked with 'Demo'?"
4
+
5
+ Seeding makes it super easy. It needs to have access to your ActiveRecord models and therefore it's best to use it with 'rails c'. I am happy to extend it for other use cases if needed.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'seeding'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install seeding
20
+
21
+ ## Usage
22
+
23
+ 1. Switch to your rails app folder
24
+ 2. Add "gem 'seeding'" to your Gemfile
25
+ 3. enter bundle on the shell
26
+ 4. Start your rails console by "rails c" or pass an Environment to it
27
+ You can pass in any model and/or query as you see fit...
28
+ Examples:
29
+ `Seeding::CreateSeed.new.query { MyModel.where("id < 10000") }`
30
+ `Seeding::CreateSeed.new.query { User.where(test: true)}`
31
+ `Seeding::CreateSeed.new.query { Category.all(:order => "name desc") }`
32
+ `Seeding::CreateSeed.new.query { Category.all(:order => "name desc", :select => "id, name, country,") }`
33
+
34
+ It then creates a file in the root directory in your application named seeding-MyModel + guid sequence to prevent accidentally overwriting
35
+
36
+ Example:
37
+ `1.9.3p0 :001 > Seeding::CreateSeed.new.query { Category.all(:order => "name desc", :select => "id, name, country, catgroup") }`
38
+
39
+ creates:
40
+
41
+
42
+
43
+
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'uuid'
3
+
4
+ module Seeding
5
+
6
+ end
7
+
8
+ directory = File.expand_path(File.dirname(__FILE__))
9
+ require File.join(directory, 'seeding', 'create_seed')
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'uuid'
3
+ module Seeding
4
+
5
+ class CreateSeed
6
+ # Pass in Activerecord query like Seedy::CreateSeed.new.query {User.where(demo_flag = true)}
7
+ def query(q={})
8
+ @seedy_result = yield
9
+ create @seedy_result
10
+ end
11
+
12
+ def create(query_results)
13
+ klass = query_results[0].class.name
14
+ # Create a uuid for the filename so it can't overwrite anything accidentially
15
+ uuid = UUID.new.generate
16
+ File.open("seeding-#{klass}-" + uuid + ".rb" , 'w') do |file|
17
+ file.puts "# -*- encoding: utf-8 -*"
18
+ query_results.each_with_index.map do |v|
19
+ attrib = v.attributes.keys
20
+ str = "#{klass}.create! "
21
+ attrib.each do |at|
22
+ if v[at].class.to_s == "Fixnum"
23
+ str << " :#{at} => #{v[at]}, "
24
+ else
25
+ str << " :#{at} => '#{v[at]}', "
26
+ end
27
+ end
28
+ str << "**"
29
+ str.gsub!(", **", "")
30
+ str << "\n"
31
+ file.puts str
32
+ file.puts "puts \".\""
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+
41
+
@@ -0,0 +1,3 @@
1
+ module Seeding
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/seeding/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Nikolai Manek"]
6
+ gem.email = ["niko.manek@gmail.com"]
7
+ gem.description = %q{Seeding creates a seed.rb from your existing database. You can write queries on the rails console and it will write the results to your seed.rb. I wrote it after having to create seed files with thousands of rows and could not handle it any longer..}
8
+ gem.summary = %q{Seeding creates a seed.rb from query results}
9
+ gem.homepage = "https://github.com/nikoma/seeding"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ #gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "seeding"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Seeding::VERSION
17
+
18
+ gem.add_runtime_dependency "uuid"
19
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seeding
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nikolai Manek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: uuid
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Seeding creates a seed.rb from your existing database. You can write
31
+ queries on the rails console and it will write the results to your seed.rb. I wrote
32
+ it after having to create seed files with thousands of rows and could not handle
33
+ it any longer..
34
+ email:
35
+ - niko.manek@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - .gitignore
41
+ - Gemfile
42
+ - LICENSE
43
+ - README.md
44
+ - Rakefile
45
+ - lib/seeding.rb
46
+ - lib/seeding/create_seed.rb
47
+ - lib/seeding/version.rb
48
+ - seeding.gemspec
49
+ homepage: https://github.com/nikoma/seeding
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Seeding creates a seed.rb from query results
73
+ test_files: []