fixtures_dumper 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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 559fdea955e905865eb880c63c3f26a2bc828b4e
4
+ data.tar.gz: e7e4ea02295e86c758f616ffea9ad70664819967
5
+ SHA512:
6
+ metadata.gz: edf7680b5f6c054b0533bfe2d38ff1664b278ff72bfbacd1bb408379ac589a687b45be1b13bd9f3025466a72fd84021f9a3d2f64e414d95bfd8da809eba79dd2
7
+ data.tar.gz: 00c83a69a25fbbc325a7bccfc79071f040726fcf8945f86e45e4018cfbce9cf4b45a82a3e4329067f8df1611bccb5b590989042b8ba77cb5eccefa51e0f13a61
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fixtures_dumper.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Prathamesh Sonpatki
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,63 @@
1
+ # FixturesDumper
2
+
3
+ Dump data from development or test database to fixtures easily.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fixtures_dumper'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fixtures_dumper
20
+
21
+ ## Supported Rails Versions
22
+
23
+ Rails 3.2.x and Rails 4.x
24
+
25
+ ## Usage
26
+
27
+ ``` ruby
28
+ rake db:fixtures:dump # Dump data in all the tables to fixtures
29
+ rake db:fixtures:dump TABLE=foo # Dump data from `foo` to its fixture file
30
+ rake db:fixtures:dump RAILS_ENV=test # Dump data from test database to fixtures
31
+ ```
32
+ ## Output
33
+
34
+ ```
35
+ $ cat users.yml
36
+ user_1:
37
+ id: 1
38
+ email: john@example.com
39
+ encrypted_password: "$2a$10$5jvZFdi7rNvn.pEACqsRtulzLIBHjTp.Fq8V4mEIN9lLRkhdjugjK"
40
+ reset_password_token:
41
+ reset_password_sent_at:
42
+ remember_created_at:
43
+ sign_in_count: 0
44
+ current_sign_in_at:
45
+ last_sign_in_at:
46
+ current_sign_in_ip:
47
+ last_sign_in_ip:
48
+ created_at: 2014-09-08 09:02:15.286126000 Z
49
+ updated_at: 2014-09-08 09:02:15.286126000 Z
50
+ last_name: Smith
51
+ first_name: John
52
+ role: super_admin
53
+ authentication_token: VPsQJyicduFU2GKJbeLz
54
+ profile_image:
55
+ ```
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/bigbinary/fixtures_dumper/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -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 'fixtures_dumper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fixtures_dumper"
8
+ spec.version = FixturesDumper::VERSION
9
+ spec.authors = ["Prathamesh Sonpatki"]
10
+ spec.email = ["csonpatki@gmail.com"]
11
+ spec.summary = %q{Dump data to fixtures easily.}
12
+ spec.description = %q{Dump data to fixtures easily.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "fixtures_dumper/version"
2
+
3
+ module FixturesDumper
4
+ require 'fixtures_dumper/railtie'
5
+ end
@@ -0,0 +1,7 @@
1
+ module FixturesDumper
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load "tasks/dump_fixtures.rake"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module FixturesDumper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,64 @@
1
+ namespace :db do
2
+ namespace :fixtures do
3
+ desc "Dumps data from database to fixtures"
4
+
5
+ task :dump => :environment do
6
+
7
+ TABLES_TO_BE_EXCLUDED = %w(schema_migrations delayed_jobs)
8
+
9
+ fixtures_path = if ENV['FIXTURES_PATH']
10
+ File.join(Rails.root, ENV['FIXTURES_PATH'])
11
+ else
12
+ File.join(Rails.root, 'test', 'fixtures')
13
+ end
14
+
15
+ connection = ActiveRecord::Base.connection
16
+
17
+ if ENV['TABLE'] && connection.tables.exclude?(ENV['TABLE'])
18
+ puts "Table #{ENV['TABLE']} does not exist in the database."
19
+ exit
20
+ end
21
+
22
+ if ENV['TABLE'] && connection.tables.include?(ENV['TABLE'])
23
+ tables = Array.wrap ENV['TABLE']
24
+ else
25
+ tables = connection.tables
26
+ end
27
+
28
+ actual_tables = tables - TABLES_TO_BE_EXCLUDED
29
+
30
+ puts "Dumping fixtures for following tables:\n" << actual_tables.join(", ")
31
+
32
+ actual_tables.each do |table|
33
+ begin
34
+ model = table.singularize.camelize.constantize
35
+ data = model.unscoped
36
+
37
+ result = []
38
+
39
+ if data.count > 0
40
+ data.each do |record|
41
+ result << { "#{table.singularize}_#{record.id}" => record.attributes }
42
+ end
43
+
44
+ fixture_file = fixtures_path + "/#{table}.yml"
45
+
46
+ puts "Dumping #{data.count} records in #{table}.yml"
47
+
48
+ File.open(fixture_file, "w") do |f|
49
+ result.each do |hash|
50
+ f.write(hash.to_yaml.gsub(/^---\s+/,''))
51
+ end
52
+ end
53
+
54
+ else
55
+ puts "Table #{table} has 0 records."
56
+ end
57
+ rescue NameError => ex
58
+ puts ex.message
59
+ next
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixtures_dumper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Prathamesh Sonpatki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-12 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ description: Dump data to fixtures easily.
42
+ email:
43
+ - csonpatki@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - fixtures_dumper.gemspec
54
+ - lib/fixtures_dumper.rb
55
+ - lib/fixtures_dumper/railtie.rb
56
+ - lib/fixtures_dumper/version.rb
57
+ - lib/tasks/dump_fixtures.rake
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Dump data to fixtures easily.
82
+ test_files: []
83
+ has_rdoc: