pad_utils 1.3.0 → 1.3.1
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.
- checksums.yaml +4 -4
- data/lib/pad_utils/pad_files.rb +6 -1
- data/lib/pad_utils/pad_text.rb +3 -0
- data/lib/pad_utils/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 670f14eb8e988c3a250ef6968c75d43255afe3dc
|
4
|
+
data.tar.gz: 794a1ff4059c81f06cf53cc4d707c73146493ceb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9967be3fb3dda66afa9328fb4702f13512a14f14557a60432a5bcc638410e76cf4f421b54b776ed621c43beca1c2e2c0a502bc766e00105d83aae9e917580a8
|
7
|
+
data.tar.gz: cc4ec2ca116fc036c0786ef5aaf1159ff715dd59d44656dce9b7ad62842875818ee9313a5435c66206cef7535598a67206b4998130d25d49a876a301748dcf1b
|
data/lib/pad_utils/pad_files.rb
CHANGED
@@ -85,7 +85,10 @@ module PadUtils
|
|
85
85
|
# @example
|
86
86
|
# PadUtils.create_directory("path/to/dir")
|
87
87
|
def self.create_directory(dir_name)
|
88
|
-
|
88
|
+
dirname = File.dirname(dir_name)
|
89
|
+
unless File.directory?(dirname)
|
90
|
+
FileUtils.mkdir_p(dirname)
|
91
|
+
end
|
89
92
|
end
|
90
93
|
|
91
94
|
# Deletes a directory and its content
|
@@ -125,6 +128,7 @@ module PadUtils
|
|
125
128
|
# @example
|
126
129
|
# PadUtils.write_to_file("path/to/file", "Hello\nThis is a test")
|
127
130
|
def self.write_to_file(filepath, content)
|
131
|
+
self.create_directory(filepath)
|
128
132
|
File.open(filepath, 'w') { |f| f.write(content)}
|
129
133
|
rescue Exception => e
|
130
134
|
PadUtils.log("Error in write_to_file", e)
|
@@ -145,6 +149,7 @@ module PadUtils
|
|
145
149
|
# @example
|
146
150
|
# PadUtils.append_to_file("path/to/file.txt", "Append this!", false)
|
147
151
|
def self.append_to_file(filepath, content, new_line = true)
|
152
|
+
self.create_directory(filepath)
|
148
153
|
content = "\n#{content}" if new_line
|
149
154
|
File.open(filepath, 'a') { |f| f.write("#{content}")}
|
150
155
|
rescue Exception => e
|
data/lib/pad_utils/pad_text.rb
CHANGED
@@ -90,6 +90,9 @@ module PadUtils
|
|
90
90
|
PadUtils.log("Error replacing #{old_text} in #{file} with #{new_text}", e)
|
91
91
|
end
|
92
92
|
|
93
|
+
# TODO: A method to get the value of an option. E.g. get :foo from Config.Bar = :foo inside a file.
|
94
|
+
# TODO: A method to set the value of an option in a file. Change the value if it exists, create it if it doesn't.
|
95
|
+
|
93
96
|
# Inserts text before the first occurence of a string.
|
94
97
|
#
|
95
98
|
# Can be used on a string or on a file.
|
data/lib/pad_utils/version.rb
CHANGED