Class: GitFriendlyDumper
- Inherits:
-
Object
- Object
- GitFriendlyDumper
- Includes:
- FileUtils
- Defined in:
- lib/git_friendly_dumper.rb,
lib/git_friendly_dumper/railtie.rb,
lib/git_friendly_dumper/version.rb
Overview
Database independent and git friendly replacement for mysqldump for rails projects
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Attribute Summary collapse
-
#clobber_fixtures ⇒ Object
(also: #clobber_fixtures?)
Returns the value of attribute clobber_fixtures.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#fixtures ⇒ Object
Returns the value of attribute fixtures.
-
#force ⇒ Object
(also: #force?)
Returns the value of attribute force.
-
#include_schema ⇒ Object
(also: #include_schema?)
Returns the value of attribute include_schema.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#path ⇒ Object
Returns the value of attribute path.
-
#raise_error ⇒ Object
(also: #raise_error?)
Returns the value of attribute raise_error.
-
#root ⇒ Object
Returns the value of attribute root.
-
#show_progress ⇒ Object
(also: #show_progress?)
Returns the value of attribute show_progress.
-
#tables ⇒ Object
Returns the value of attribute tables.
Class Method Summary collapse
Instance Method Summary collapse
- #dump ⇒ Object
-
#initialize(options = {}) ⇒ GitFriendlyDumper
constructor
A new instance of GitFriendlyDumper.
- #load ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GitFriendlyDumper
Returns a new instance of GitFriendlyDumper.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/git_friendly_dumper.rb', line 30 def initialize( = {}) .assert_valid_keys(:root, :path, :connection, :connection_name, :tables, :force, :include_schema, :show_progress, :clobber_fixtures, :limit, :raise_error, :fixtures, :fixtures_file) self.root = [:root] || (defined?(Rails) && Rails.root) || pwd if [:fixtures_file] raise ArgumentError, "GitFriendlyDumper cannot specify both :fixtures and :fixtures_file" if [:fixtures].present? [:fixtures] = File.read([:fixtures_file]).split("\n").map(&:squish).reject(&:blank?) end if [:fixtures] && ([:include_schema] || [:clobber_fixtures]) raise ArgumentError, "GitFriendlyDumper if :fixtures option given, neither :include_schema nor :clobber_fixtures can be given" end if [:show_progress] && !defined?(ProgressBar) raise RuntimeError, "GitFriendlyDumper requires the progressbar gem for progress option.\n sudo gem install progressbar" end self.path = File.([:path] || 'db/dump') self.tables = [:tables] self.fixtures = [:fixtures] self.limit = .key?(:limit) ? [:limit].to_i : 2500 self.raise_error = .key?(:raise_error) ? [:raise_error] : true self.force = .key?(:force) ? [:force] : false self.include_schema = .key?(:include_schema) ? [:include_schema] : false self.show_progress = .key?(:show_progress) ? [:show_progress] : false self.clobber_fixtures = .key?(:clobber_fixtures) ? [:clobber_fixtures] : ([:tables].blank? ? true : false) self.connection = [:connection] || begin if [:connection_name] ActiveRecord::Base.establish_connection([:connection_name]) end ActiveRecord::Base.connection end end |
Instance Attribute Details
#clobber_fixtures ⇒ Object Also known as: clobber_fixtures?
Returns the value of attribute clobber_fixtures.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def clobber_fixtures @clobber_fixtures end |
#connection ⇒ Object
Returns the value of attribute connection.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def connection @connection end |
#fixtures ⇒ Object
Returns the value of attribute fixtures.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def fixtures @fixtures end |
#force ⇒ Object Also known as: force?
Returns the value of attribute force.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def force @force end |
#include_schema ⇒ Object Also known as: include_schema?
Returns the value of attribute include_schema.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def include_schema @include_schema end |
#limit ⇒ Object
Returns the value of attribute limit.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def limit @limit end |
#path ⇒ Object
Returns the value of attribute path.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def path @path end |
#raise_error ⇒ Object Also known as: raise_error?
Returns the value of attribute raise_error.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def raise_error @raise_error end |
#root ⇒ Object
Returns the value of attribute root.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def root @root end |
#show_progress ⇒ Object Also known as: show_progress?
Returns the value of attribute show_progress.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def show_progress @show_progress end |
#tables ⇒ Object
Returns the value of attribute tables.
13 14 15 |
# File 'lib/git_friendly_dumper.rb', line 13 def tables @tables end |
Class Method Details
.dump(options = {}) ⇒ Object
21 22 23 |
# File 'lib/git_friendly_dumper.rb', line 21 def dump( = {}) new().dump end |
.load(options = {}) ⇒ Object
25 26 27 |
# File 'lib/git_friendly_dumper.rb', line 25 def load( = {}) new().load end |
Instance Method Details
#dump ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/git_friendly_dumper.rb', line 65 def dump if fixtures raise ArgumentError, "Cannot dump when :fixtures option is given" end self.tables ||= db_tables tables.delete('schema_migrations') unless include_schema? if force? || (tables & fixtures_tables).empty? || confirm?(:dump) puts "Dumping data#{' and structure' if include_schema?} from #{current_database_name} to #{path.sub("#{root}/",'')}\n" clobber_all_fixtures if clobber_fixtures? connection.transaction do tables.each {|table| dump_table(table) } end end end |
#load ⇒ Object
80 81 82 |
# File 'lib/git_friendly_dumper.rb', line 80 def load fixtures ? load_fixtures : load_tables end |