strap 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/strap/cli.rb CHANGED
@@ -55,14 +55,15 @@ module Strap
55
55
  config.db_port,
56
56
  config.db_host)
57
57
 
58
- config.run_rename_files
59
58
  config.run_change_permissions
59
+ config.run_replace
60
+ config.run_rename_files
60
61
 
61
62
  core.commit_to_repo(config.destination_repo)
62
63
 
63
64
  config.run_after_bootstrap
64
65
  end
65
-
66
+
66
67
  end
67
68
 
68
69
  end
data/lib/strap/config.rb CHANGED
@@ -4,11 +4,12 @@ module Strap
4
4
 
5
5
  attr_accessor :db_name, :db_user, :db_password, :db_socket, :db_host, :db_port,
6
6
  :sql, :source_repo, :destination_repo, :after, :files_to_rename,
7
- :files_to_change_permissions_on
7
+ :files_to_change_permissions_on, :to_replace
8
8
 
9
9
  def initialize(file)
10
10
  self.files_to_rename = []
11
11
  self.files_to_change_permissions_on = []
12
+ self.to_replace = []
12
13
  instance_eval File.read(file)
13
14
  end
14
15
 
@@ -38,13 +39,29 @@ module Strap
38
39
  def change_permissions(permission, file)
39
40
  self.files_to_change_permissions_on << [permission, file]
40
41
  end
41
-
42
+
42
43
  def run_change_permissions
43
44
  return false unless files_to_change_permissions_on.length > 0
44
45
  files_to_change_permissions_on.each do |file|
45
46
  File.chmod file[0], file[1]
46
47
  end
47
48
  end
49
+
50
+ def replace_text(file, search, replace)
51
+ self.to_replace << [file, search, replace]
52
+ end
53
+
54
+ def run_replace
55
+ return false unless to_replace.length > 0
56
+ to_replace.each do |search|
57
+ file = search[0]
58
+ text = File.read(file)
59
+ updated_text = text.gsub(/#{search[1]}/, search[2])
60
+ File.open(file, "w") do |file|
61
+ file.puts updated_text
62
+ end
63
+ end
64
+ end
48
65
 
49
66
  end
50
67
 
data/lib/strap/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Strap
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -31,6 +31,9 @@ set :source_repo, ""
31
31
  ## Use this to rename a file before it gets committed to new repo
32
32
  # rename_file "path/to/old_name", "path/to/new_name"
33
33
 
34
+ ## Use this to search and replace text within a file
35
+ # replace_text "path/to/file", "text to replace", "replacement text"
36
+
34
37
  ## Use this to change permissions of a file before it gets committed
35
38
  # change_permissions 0777, "change_permissions"
36
39
 
@@ -9,6 +9,9 @@ describe Strap::Config do
9
9
  File.new("old_name", "w")
10
10
  File.new("old_name_2", "w")
11
11
  File.new("change_permissions", "w")
12
+ File.open("search", "w") do |file|
13
+ file.puts "replace me!"
14
+ end
12
15
  @core = Strap::Core.new
13
16
  @core.create_project_directory(@path)
14
17
  @core.create_config(@path)
@@ -20,6 +23,7 @@ describe Strap::Config do
20
23
  FileUtils.remove_file("new_name") if File.file?("new_name")
21
24
  FileUtils.remove_file("new_name_2") if File.file?("new_name_2")
22
25
  FileUtils.remove_file("change_permissions") if File.file?("change_permissions")
26
+ FileUtils.remove_file("search") if File.file?("search")
23
27
  FileUtils.remove_dir(@path) if File.directory?(@path)
24
28
  end
25
29
 
@@ -61,6 +65,14 @@ describe Strap::Config do
61
65
  File.stat("change_permissions").mode.must_equal 33279
62
66
  end
63
67
 
68
+ it "should search and replace within file" do
69
+ File.file?("search").must_equal true
70
+ @config = Strap::Config.new("test/lib/templates/#{Strap::CONFIG_FILENAME}")
71
+ @config.run_replace
72
+ has_replaced_text = open("search") { |f| f.grep(/I'm replaced/) }
73
+ has_replaced_text.length.must_equal 1
74
+ end
75
+
64
76
  end
65
77
 
66
78
  module Strap
@@ -10,6 +10,8 @@ set :destination_repo, Strap::Test::DESTINATION_REPO
10
10
  rename_file "old_name", "new_name"
11
11
  rename_file "old_name_2", "new_name_2"
12
12
 
13
+ replace_text "search", "replace me!", "I'm replaced!"
14
+
13
15
  change_permissions 0777, "change_permissions"
14
16
 
15
17
  after_bootstrap do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: