Class: Config
- Inherits:
-
Object
- Object
- Config
- Defined in:
- lib/config.rb
Overview
Read configuration file
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#downgrade ⇒ Object
readonly
Returns the value of attribute downgrade.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#upgrade ⇒ Object
readonly
Returns the value of attribute upgrade.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
-
#version0 ⇒ Object
readonly
Returns the value of attribute version0.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#version(path) ⇒ Object
Extract version number from the SQL script path name Version is text between last ‘/’ and ‘_’ File path must end with ‘.sql’.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/config.rb', line 8 def initialize @env = ENV['env'] @env = 'dev' if @env.nil? config = Pyer::Properties.new("config/#{@env}") @host = config.host @port = config.port @username = config.username @password = config.password @database = config.database @version0 = config.version0 @upgrade = config.upgrade @downgrade = config.downgrade @verbose = ENV['verbose'] == 'true' end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
6 7 8 |
# File 'lib/config.rb', line 6 def database @database end |
#downgrade ⇒ Object (readonly)
Returns the value of attribute downgrade.
6 7 8 |
# File 'lib/config.rb', line 6 def downgrade @downgrade end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/config.rb', line 6 def env @env end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/config.rb', line 6 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
6 7 8 |
# File 'lib/config.rb', line 6 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/config.rb', line 6 def port @port end |
#upgrade ⇒ Object (readonly)
Returns the value of attribute upgrade.
6 7 8 |
# File 'lib/config.rb', line 6 def upgrade @upgrade end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
6 7 8 |
# File 'lib/config.rb', line 6 def username @username end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
6 7 8 |
# File 'lib/config.rb', line 6 def verbose @verbose end |
#version0 ⇒ Object (readonly)
Returns the value of attribute version0.
6 7 8 |
# File 'lib/config.rb', line 6 def version0 @version0 end |
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/config.rb', line 23 def create Dir.mkdir 'config' unless File.exist?('config') File.open("config/#{@env}", 'w') do |f| f.write("database = \n") f.write("host = localhost\n") f.write("port = 5432\n") f.write("username = \n") f.write("password = \n") f.write("encoding = utf8\n") f.write("version0 = 0.00\n") f.write("upgrade = migrations/*_up_*.sql\n") f.write("downgrade = migrations/*_down_*.sql\n") end unless File.exist?("config/#{@env}") end |
#version(path) ⇒ Object
Extract version number from the SQL script path name Version is text between last ‘/’ and ‘_’ File path must end with ‘.sql’
41 42 43 |
# File 'lib/config.rb', line 41 def version(path) path.gsub(%r{.*/}, '').gsub(/_.*\.sql/, '') end |