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.2"
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.
29 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 |
# File 'lib/git_friendly_dumper.rb', line 29 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.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def clobber_fixtures @clobber_fixtures end |
#connection ⇒ Object
Returns the value of attribute connection.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def connection @connection end |
#fixtures ⇒ Object
Returns the value of attribute fixtures.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def fixtures @fixtures end |
#force ⇒ Object Also known as: force?
Returns the value of attribute force.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def force @force end |
#include_schema ⇒ Object Also known as: include_schema?
Returns the value of attribute include_schema.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def include_schema @include_schema end |
#limit ⇒ Object
Returns the value of attribute limit.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def limit @limit end |
#path ⇒ Object
Returns the value of attribute path.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def path @path end |
#raise_error ⇒ Object Also known as: raise_error?
Returns the value of attribute raise_error.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def raise_error @raise_error end |
#root ⇒ Object
Returns the value of attribute root.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def root @root end |
#show_progress ⇒ Object Also known as: show_progress?
Returns the value of attribute show_progress.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def show_progress @show_progress end |
#tables ⇒ Object
Returns the value of attribute tables.
12 13 14 |
# File 'lib/git_friendly_dumper.rb', line 12 def tables @tables end |
Class Method Details
.dump(options = {}) ⇒ Object
20 21 22 |
# File 'lib/git_friendly_dumper.rb', line 20 def dump( = {}) new().dump end |
.load(options = {}) ⇒ Object
24 25 26 |
# File 'lib/git_friendly_dumper.rb', line 24 def load( = {}) new().load end |
Instance Method Details
#dump ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/git_friendly_dumper.rb', line 64 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
79 80 81 |
# File 'lib/git_friendly_dumper.rb', line 79 def load fixtures ? load_fixtures : load_tables end |