db_fixtures_dump 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify gem's dependencies in db_fixtures_dump.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kurt Thams
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.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # DbFixturesDump
2
+
3
+ Adds db:fixtures:dump rake task to dump all tables into yaml fixtures
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'db_fixtures_dump'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install db_fixtures_dump
18
+
19
+ ## Usage
20
+
21
+ $ rake db:fixtures:dump
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
30
+
31
+ ## References
32
+
33
+ Original gists:
34
+
35
+ http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
36
+ https://gist.github.com/iiska/1527911
37
+
38
+
39
+ Gemification:
40
+ http://blog.nathanhumbert.com/2010/02/rails-3-loading-rake-tasks-from-gem.html
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'db_fixtures_dump/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "db_fixtures_dump"
8
+ spec.version = DbFixturesDump::VERSION
9
+ spec.authors = ["Kurt Thams"]
10
+ spec.email = ["thams@thams.com"]
11
+ spec.description = %q{Rake task to dump all tables into yaml fixtures}
12
+ spec.summary = %q{Rake task to dump all tables into yaml fixtures}
13
+ spec.homepage = "https://github.com/thams/db_fixtures_dump"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,11 @@
1
+ require 'db_fixtures_dump'
2
+ require 'rails'
3
+ module DBFixturesDump
4
+ class Railtie < Rails::Railtie
5
+ railtie_name :db_fixtures_dump
6
+
7
+ rake_tasks do
8
+ load "tasks/db_fixtures_dump.rake"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module DbFixturesDump
2
+ VERSION = "0.0.9"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "db_fixtures_dump/version"
2
+
3
+ module DbFixturesDump
4
+ require 'db_fixtures_dump/railtie' if defined?(Rails)
5
+ end
@@ -0,0 +1,47 @@
1
+ # Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
2
+ #
3
+ # Optimized version which uses to_yaml for content creation and checks
4
+ # that models are ActiveRecord::Base models before trying to fetch
5
+ # them from database.
6
+
7
+ # Then forked from https://gist.github.com/iiska/1527911
8
+ #
9
+ # fixed obsolete use of RAILS_ROOT, glob
10
+ # put output in the spec/fixtures directory instead of test/fixtures
11
+
12
+ namespace :db do
13
+ namespace :fixtures do
14
+ desc 'Dumps all models into fixtures.'
15
+ task :dump => :environment do
16
+ models = Dir.glob(Rails.root + 'app/models/**.rb').map do |s|
17
+ Pathname.new(s).basename.to_s.gsub(/\.rb$/,'').camelize
18
+ end
19
+
20
+ puts "Found models: " + models.join(', ')
21
+
22
+ models.each do |m|
23
+ model = m.constantize
24
+ next unless model.ancestors.include?(ActiveRecord::Base)
25
+
26
+ puts "Dumping model: " + m
27
+ entries = model.find(:all, :order => 'id ASC')
28
+
29
+ increment = 1
30
+
31
+ # use test/fixtures if you do test:unit
32
+ model_file = Rails.root + ('spec/fixtures/' + m.underscore.pluralize + '.yml')
33
+ File.open(model_file, 'w') do |f|
34
+ entries.each do |a|
35
+ attrs = a.attributes
36
+ attrs.delete_if{|k,v| v.blank?}
37
+
38
+ output = {m + '_' + increment.to_s => attrs}
39
+ f << output.to_yaml.gsub(/^--- \n/,'') + "\n"
40
+
41
+ increment += 1
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: db_fixtures_dump
3
+ version: !ruby/object:Gem::Version
4
+ hash: 13
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 9
10
+ version: 0.0.9
11
+ platform: ruby
12
+ authors:
13
+ - Kurt Thams
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-10-29 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 9
30
+ segments:
31
+ - 1
32
+ - 3
33
+ version: "1.3"
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: Rake task to dump all tables into yaml fixtures
51
+ email:
52
+ - thams@thams.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - Gemfile
61
+ - LICENSE.txt
62
+ - README.md
63
+ - Rakefile
64
+ - db_fixtures_dump.gemspec
65
+ - lib/db_fixtures_dump.rb
66
+ - lib/db_fixtures_dump/railtie.rb
67
+ - lib/db_fixtures_dump/version.rb
68
+ - lib/tasks/db_fixtures_dump.rake
69
+ has_rdoc: true
70
+ homepage: https://github.com/thams/db_fixtures_dump
71
+ licenses:
72
+ - MIT
73
+ post_install_message:
74
+ rdoc_options: []
75
+
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.7
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Rake task to dump all tables into yaml fixtures
103
+ test_files: []
104
+