Class: Strap::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/strap/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.files_to_change_permissions_on = []
  self.to_replace = []
  instance_eval File.read(file)
end

Instance Attribute Details

#afterObject

Returns the value of attribute after.



5
6
7
# File 'lib/strap/config.rb', line 5

def after
  @after
end

#db_hostObject

Returns the value of attribute db_host.



5
6
7
# File 'lib/strap/config.rb', line 5

def db_host
  @db_host
end

#db_nameObject

Returns the value of attribute db_name.



5
6
7
# File 'lib/strap/config.rb', line 5

def db_name
  @db_name
end

#db_passwordObject

Returns the value of attribute db_password.



5
6
7
# File 'lib/strap/config.rb', line 5

def db_password
  @db_password
end

#db_portObject

Returns the value of attribute db_port.



5
6
7
# File 'lib/strap/config.rb', line 5

def db_port
  @db_port
end

#db_socketObject

Returns the value of attribute db_socket.



5
6
7
# File 'lib/strap/config.rb', line 5

def db_socket
  @db_socket
end

#db_userObject

Returns the value of attribute db_user.



5
6
7
# File 'lib/strap/config.rb', line 5

def db_user
  @db_user
end

#destination_repoObject

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_onObject

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
  @files_to_change_permissions_on
end

#files_to_renameObject

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_repoObject

Returns the value of attribute source_repo.



5
6
7
# File 'lib/strap/config.rb', line 5

def source_repo
  @source_repo
end

#sqlObject

Returns the value of attribute sql.



5
6
7
# File 'lib/strap/config.rb', line 5

def sql
  @sql
end

#to_replaceObject

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 change_permissions(permission, file)
  self.files_to_change_permissions_on << [permission, 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_bootstrapObject



24
25
26
# File 'lib/strap/config.rb', line 24

def run_after_bootstrap
  instance_eval &after if after
end

#run_change_permissionsObject



43
44
45
46
47
48
# File 'lib/strap/config.rb', line 43

def run_change_permissions
  return false unless files_to_change_permissions_on.length > 0
    files_to_change_permissions_on.each do |file|
    File.chmod file[0], file[1]
  end
end

#run_rename_filesObject



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_replaceObject



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