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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d62721ccb2c8956e21afbd46701f70c4ed8b16d0
4
- data.tar.gz: 880ccaa96f429c75831085cfaa4c06993bb3beb0
3
+ metadata.gz: 670f14eb8e988c3a250ef6968c75d43255afe3dc
4
+ data.tar.gz: 794a1ff4059c81f06cf53cc4d707c73146493ceb
5
5
  SHA512:
6
- metadata.gz: 58c650731599b21858389934b0223cfd59780eca5e0206a345b8cf4878ca21a67233e09034c8cb4dc46240d311838d2989ff481ec285231b5fa5eb36a51fb6c2
7
- data.tar.gz: f82659ed6c0f39447f064d2e9916c7b7078c145bb7c4d152bd4155d19810c0a0d76d2f3d40430ffce85ce7e261c91ad6310c18a42872b51859d8f96309e61202
6
+ metadata.gz: e9967be3fb3dda66afa9328fb4702f13512a14f14557a60432a5bcc638410e76cf4f421b54b776ed621c43beca1c2e2c0a502bc766e00105d83aae9e917580a8
7
+ data.tar.gz: cc4ec2ca116fc036c0786ef5aaf1159ff715dd59d44656dce9b7ad62842875818ee9313a5435c66206cef7535598a67206b4998130d25d49a876a301748dcf1b
@@ -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
- FileUtils.mkdir_p(dir_name)
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
@@ -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.
@@ -1,4 +1,4 @@
1
1
  module PadUtils
2
2
  # PadUtils version number
3
- VERSION = "1.3.0"
3
+ VERSION = "1.3.1"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pad_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Schuele