strap 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/strap/cli.rb +3 -0
- data/lib/strap/config.rb +22 -3
- data/lib/strap/version.rb +1 -1
- data/test/lib/strap/test_config.rb +12 -0
- data/test/lib/templates/Strapfile +1 -0
- metadata +1 -1
data/lib/strap/cli.rb
CHANGED
data/lib/strap/config.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
|
+
require 'debugger'
|
2
|
+
|
1
3
|
module Strap
|
2
4
|
|
3
5
|
class Config
|
4
6
|
|
5
7
|
attr_accessor :db_name, :db_user, :db_password, :db_socket, :db_host, :db_port,
|
6
|
-
:sql, :source_repo, :destination_repo, :after
|
8
|
+
:sql, :source_repo, :destination_repo, :after, :files_to_rename,
|
9
|
+
:files_to_change_permissions_on
|
7
10
|
|
8
11
|
def initialize(file)
|
12
|
+
self.files_to_rename = []
|
13
|
+
self.files_to_change_permissions_on = []
|
9
14
|
instance_eval File.read(file)
|
10
15
|
end
|
11
16
|
|
@@ -22,11 +27,25 @@ module Strap
|
|
22
27
|
end
|
23
28
|
|
24
29
|
def rename_file(old_name, new_name)
|
25
|
-
|
30
|
+
self.files_to_rename << [old_name, new_name]
|
31
|
+
end
|
32
|
+
|
33
|
+
def run_rename_files
|
34
|
+
return false unless files_to_rename.length > 0
|
35
|
+
files_to_rename.each do |file|
|
36
|
+
File.rename(file[0], file[1])
|
37
|
+
end
|
26
38
|
end
|
27
39
|
|
28
40
|
def change_permissions(permission, file)
|
29
|
-
|
41
|
+
self.files_to_change_permissions_on << [permission, file]
|
42
|
+
end
|
43
|
+
|
44
|
+
def run_change_permissions
|
45
|
+
return false unless files_to_change_permissions_on.length > 0
|
46
|
+
files_to_change_permissions_on.each do |file|
|
47
|
+
File.chmod file[0], file[1]
|
48
|
+
end
|
30
49
|
end
|
31
50
|
|
32
51
|
end
|
data/lib/strap/version.rb
CHANGED
@@ -7,6 +7,7 @@ describe Strap::Config do
|
|
7
7
|
before do
|
8
8
|
@path = "test_path"
|
9
9
|
File.new("old_name", "w")
|
10
|
+
File.new("old_name_2", "w")
|
10
11
|
File.new("change_permissions", "w")
|
11
12
|
@core = Strap::Core.new
|
12
13
|
@core.create_project_directory(@path)
|
@@ -15,7 +16,9 @@ describe Strap::Config do
|
|
15
16
|
|
16
17
|
after do
|
17
18
|
FileUtils.remove_file("old_name") if File.file?("old_name")
|
19
|
+
FileUtils.remove_file("old_name_2") if File.file?("old_name_2")
|
18
20
|
FileUtils.remove_file("new_name") if File.file?("new_name")
|
21
|
+
FileUtils.remove_file("new_name_2") if File.file?("new_name_2")
|
19
22
|
FileUtils.remove_file("change_permissions") if File.file?("change_permissions")
|
20
23
|
FileUtils.remove_dir(@path) if File.directory?(@path)
|
21
24
|
end
|
@@ -41,11 +44,20 @@ describe Strap::Config do
|
|
41
44
|
it "should rename a file" do
|
42
45
|
File.file?("old_name").must_equal true
|
43
46
|
@config = Strap::Config.new("test/lib/templates/#{Strap::CONFIG_FILENAME}")
|
47
|
+
@config.run_rename_files
|
44
48
|
File.file?("new_name").must_equal true
|
45
49
|
end
|
46
50
|
|
51
|
+
it "should rename multiple files" do
|
52
|
+
File.file?("old_name_2").must_equal true
|
53
|
+
@config = Strap::Config.new("test/lib/templates/#{Strap::CONFIG_FILENAME}")
|
54
|
+
@config.run_rename_files
|
55
|
+
File.file?("new_name_2").must_equal true
|
56
|
+
end
|
57
|
+
|
47
58
|
it "should change file permissions" do
|
48
59
|
@config = Strap::Config.new("test/lib/templates/#{Strap::CONFIG_FILENAME}")
|
60
|
+
@config.run_change_permissions
|
49
61
|
File.stat("change_permissions").mode.must_equal 33279
|
50
62
|
end
|
51
63
|
|