Class: Strap::Config
- Inherits:
-
Object
- Object
- Strap::Config
- Defined in:
- lib/strap/config.rb
Instance Attribute Summary collapse
-
#after ⇒ Object
Returns the value of attribute after.
-
#db_host ⇒ Object
Returns the value of attribute db_host.
-
#db_name ⇒ Object
Returns the value of attribute db_name.
-
#db_password ⇒ Object
Returns the value of attribute db_password.
-
#db_port ⇒ Object
Returns the value of attribute db_port.
-
#db_socket ⇒ Object
Returns the value of attribute db_socket.
-
#db_user ⇒ Object
Returns the value of attribute db_user.
-
#destination_repo ⇒ Object
Returns the value of attribute destination_repo.
-
#files_to_change_permissions_on ⇒ Object
Returns the value of attribute files_to_change_permissions_on.
-
#files_to_rename ⇒ Object
Returns the value of attribute files_to_rename.
-
#source_repo ⇒ Object
Returns the value of attribute source_repo.
-
#sql ⇒ Object
Returns the value of attribute sql.
-
#to_replace ⇒ Object
Returns the value of attribute to_replace.
Instance Method Summary collapse
- #after_bootstrap(&block) ⇒ Object
- #change_permissions(permission, file) ⇒ Object
-
#initialize(file) ⇒ Config
constructor
A new instance of Config.
- #rename_file(old_name, new_name) ⇒ Object
- #replace_text(file, search, replace) ⇒ Object
- #run_after_bootstrap ⇒ Object
- #run_change_permissions ⇒ Object
- #run_rename_files ⇒ Object
- #run_replace ⇒ Object
- #set(key, value) ⇒ Object
Constructor Details
#initialize(file) ⇒ Config
Returns a new instance of Config.
9 10 11 12 13 14 |
# File 'lib/strap/config.rb', line 9 def initialize(file) self.files_to_rename = [] self. = [] self.to_replace = [] instance_eval File.read(file) end |
Instance Attribute Details
#after ⇒ Object
Returns the value of attribute after.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def after @after end |
#db_host ⇒ Object
Returns the value of attribute db_host.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def db_host @db_host end |
#db_name ⇒ Object
Returns the value of attribute db_name.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def db_name @db_name end |
#db_password ⇒ Object
Returns the value of attribute db_password.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def db_password @db_password end |
#db_port ⇒ Object
Returns the value of attribute db_port.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def db_port @db_port end |
#db_socket ⇒ Object
Returns the value of attribute db_socket.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def db_socket @db_socket end |
#db_user ⇒ Object
Returns the value of attribute db_user.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def db_user @db_user end |
#destination_repo ⇒ Object
Returns the value of attribute destination_repo.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def destination_repo @destination_repo end |
#files_to_change_permissions_on ⇒ Object
Returns the value of attribute files_to_change_permissions_on.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def @files_to_change_permissions_on end |
#files_to_rename ⇒ Object
Returns the value of attribute files_to_rename.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def files_to_rename @files_to_rename end |
#source_repo ⇒ Object
Returns the value of attribute source_repo.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def source_repo @source_repo end |
#sql ⇒ Object
Returns the value of attribute sql.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def sql @sql end |
#to_replace ⇒ Object
Returns the value of attribute to_replace.
5 6 7 |
# File 'lib/strap/config.rb', line 5 def to_replace @to_replace end |
Instance Method Details
#after_bootstrap(&block) ⇒ Object
20 21 22 |
# File 'lib/strap/config.rb', line 20 def after_bootstrap(&block) self.after = block end |
#change_permissions(permission, file) ⇒ Object
39 40 41 |
# File 'lib/strap/config.rb', line 39 def (, file) self. << [, file] end |
#rename_file(old_name, new_name) ⇒ Object
28 29 30 |
# File 'lib/strap/config.rb', line 28 def rename_file(old_name, new_name) self.files_to_rename << [old_name, new_name] end |
#replace_text(file, search, replace) ⇒ Object
50 51 52 |
# File 'lib/strap/config.rb', line 50 def replace_text(file, search, replace) self.to_replace << [file, search, replace] end |
#run_after_bootstrap ⇒ Object
24 25 26 |
# File 'lib/strap/config.rb', line 24 def run_after_bootstrap instance_eval &after if after end |
#run_change_permissions ⇒ Object
43 44 45 46 47 48 |
# File 'lib/strap/config.rb', line 43 def return false unless .length > 0 .each do |file| File.chmod file[0], file[1] end end |
#run_rename_files ⇒ Object
32 33 34 35 36 37 |
# File 'lib/strap/config.rb', line 32 def run_rename_files return false unless files_to_rename.length > 0 files_to_rename.each do |file| File.rename(file[0], file[1]) end end |
#run_replace ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/strap/config.rb', line 54 def run_replace return false unless to_replace.length > 0 to_replace.each do |search| file = search[0] text = File.read(file) updated_text = text.gsub(/#{search[1]}/, search[2]) File.open(file, "w") do |file| file.puts updated_text end end end |
#set(key, value) ⇒ Object
16 17 18 |
# File 'lib/strap/config.rb', line 16 def set(key, value) instance_variable_set("@#{key}", value) end |