Class: MysqlInspector::Config
- Inherits:
-
Object
- Object
- MysqlInspector::Config
- Defined in:
- lib/mysql_inspector/config.rb
Instance Attribute Summary collapse
-
#database_name ⇒ Object
Returns the value of attribute database_name.
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#migrations ⇒ Object
Returns the value of attribute migrations.
-
#mysql_binary ⇒ Object
Returns the value of attribute mysql_binary.
-
#mysql_password ⇒ Object
Returns the value of attribute mysql_password.
-
#mysql_user ⇒ Object
Config.
-
#rails ⇒ Object
Returns the value of attribute rails.
Instance Method Summary collapse
- #access ⇒ Object
-
#create_dump(version) ⇒ Object
API.
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_dump(version) ⇒ Object
-
#load_rails_env! ⇒ Object
Impl.
- #rails! ⇒ Object
- #write_dump(version) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
4 5 6 7 8 9 10 11 |
# File 'lib/mysql_inspector/config.rb', line 4 def initialize @mysql_user = "root" @mysql_password = nil @mysql_binary = "mysql" @dir = File.(Dir.pwd) @migrations = false @rails = false end |
Instance Attribute Details
#database_name ⇒ Object
Returns the value of attribute database_name.
21 22 23 |
# File 'lib/mysql_inspector/config.rb', line 21 def database_name @database_name end |
#dir ⇒ Object
Returns the value of attribute dir.
22 23 24 |
# File 'lib/mysql_inspector/config.rb', line 22 def dir @dir end |
#migrations ⇒ Object
Returns the value of attribute migrations.
24 25 26 |
# File 'lib/mysql_inspector/config.rb', line 24 def migrations @migrations end |
#mysql_binary ⇒ Object
Returns the value of attribute mysql_binary.
19 20 21 |
# File 'lib/mysql_inspector/config.rb', line 19 def mysql_binary @mysql_binary end |
#mysql_password ⇒ Object
Returns the value of attribute mysql_password.
18 19 20 |
# File 'lib/mysql_inspector/config.rb', line 18 def mysql_password @mysql_password end |
#mysql_user ⇒ Object
Config
17 18 19 |
# File 'lib/mysql_inspector/config.rb', line 17 def mysql_user @mysql_user end |
#rails ⇒ Object
Returns the value of attribute rails.
25 26 27 |
# File 'lib/mysql_inspector/config.rb', line 25 def rails @rails end |
Instance Method Details
#access ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/mysql_inspector/config.rb', line 73 def access load_rails_env! if migrations MysqlInspector::AR::Access.new(ActiveRecord::Base.connection) else MysqlInspector::Access.new(database_name, mysql_user, mysql_password, mysql_binary) end end |
#create_dump(version) ⇒ Object
API
37 38 39 40 41 42 43 |
# File 'lib/mysql_inspector/config.rb', line 37 def create_dump(version) raise ["Missing dir or version", dir, version].inspect if dir.nil? or version.nil? file = File.join(dir, version) extras = [] extras << Migrations.new(file) if migrations Dump.new(file, *extras) end |
#load_dump(version) ⇒ Object
49 50 51 |
# File 'lib/mysql_inspector/config.rb', line 49 def load_dump(version) create_dump(version).load!(access) end |
#load_rails_env! ⇒ Object
Impl
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mysql_inspector/config.rb', line 57 def load_rails_env! if rails if !defined?(Rails) rails_env = File.('config/environment', Dir.pwd) if File.exist?(rails_env + ".rb") require rails_env end end if database_name config = ActiveRecord::Base.configurations[database_name] config or raise MysqlInspector::Access::Error, "The database configuration #{database_name.inspect} does not exist" ActiveRecord::Base.establish_connection(config) end end end |
#rails! ⇒ Object
27 28 29 30 31 |
# File 'lib/mysql_inspector/config.rb', line 27 def rails! @rails = true @migrations = true @dir = "db" end |
#write_dump(version) ⇒ Object
45 46 47 |
# File 'lib/mysql_inspector/config.rb', line 45 def write_dump(version) create_dump(version).write!(access) end |