moonshard 0.2.0 → 0.4.0

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/moonshard.rb +31 -69
  3. data/moonshard.gemspec +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb2e17a8f3e7a1f56fe38a9d86b0b501cbd501b8aacff719a971722c81b48a17
4
- data.tar.gz: 6eb0a0623a262704722ab450d4fcc85abd03aeed0618069ffdbb4e75ee784406
3
+ metadata.gz: d18c56c8d60d654600cf9681405d9abf4420e430c98eaff816861c7eadece4ae
4
+ data.tar.gz: 3da4545e60a4fdefd3a2be759eadacae9d9fa6e415eba6f899ed69472709bf1e
5
5
  SHA512:
6
- metadata.gz: fdf59f4c2fdf7ddbb026e4d786935d1b222bf248a925a06a80a6ba9f4d0ac9206ec91222374e5e3af4eaff7d3a11795fcab9cf4cc1d9a9dd923cf9399f21c65c
7
- data.tar.gz: 0a75156a8a73c972c75fca4fef0227f5aad82cfebcf8da8d1ea2ecd3f22cc24a2918d24cca4c3063a07f3c8f3d25316731c03a69145a86ca94edcc15ef0b0079
6
+ metadata.gz: 8eafa7bd31a734ba77b4a5b1d3fe46c268c3eef1b188c23f0b748ca3e9da923b57e4e721869b31b46b25ce79628ec8faa15532d2938621819324dcff29185be9
7
+ data.tar.gz: 949cde414a606d182d34955bf719621684f4e00b44cb066e343a23d9d48d63d7870b5aa071a696adcb5dbe76378ebcb220450cc7c52c0679ef16425de114cfeb
data/lib/moonshard.rb CHANGED
@@ -29,7 +29,7 @@ module Moonshard
29
29
 
30
30
  original_files.each do |file, content|
31
31
  begin
32
- File.binwrite(file, content)
32
+ File.write(file, content)
33
33
  puts "Restored: #{file}"
34
34
  rescue => e
35
35
  warn "Warning: cannot restore #{file}: #{e.message}"
@@ -54,89 +54,51 @@ module Moonshard
54
54
  next if File.expand_path(file) == backup_file
55
55
 
56
56
  begin
57
- # Read as binary so arbitrary files don't cause
58
- # invalid UTF-8 errors.
59
- content = File.binread(file)
57
+ content = File.read(file)
60
58
  rescue => e
61
59
  warn "Warning: cannot read #{file}: #{e.message}"
62
60
  next
63
61
  end
64
62
 
65
- # ##{ is ASCII, so this check is safe even for binary data.
66
- next unless content.include?("##{")
63
+ # Only process files containing ##{...}
64
+ next unless content.match?(/##\{[^}]+\}/)
67
65
 
68
- begin
69
- # The replacement syntax is text-based.
70
- # Skip files that aren't valid UTF-8.
71
- text = content.force_encoding(Encoding::UTF_8)
72
-
73
- unless text.valid_encoding?
74
- warn "Skipping binary/non-UTF-8 file: #{file}"
75
- next
76
- end
77
-
78
- # Save original content before replacement.
79
- original_files[file] = text
66
+ # Save original content before replacement
67
+ original_files[file] = content
80
68
 
81
- file_dir = File.dirname(file)
69
+ file_dir = File.dirname(file)
82
70
 
83
- replaced = text.gsub(/^([ \t]*)##\{([^}]+)\}[ \t]*$/) do
84
- indentation = Regexp.last_match(1)
85
- referenced_file = Regexp.last_match(2)
86
-
87
- referenced_path = File.expand_path(
88
- referenced_file,
89
- file_dir
90
- )
91
-
92
- unless File.file?(referenced_path)
93
- warn "Warning: file not found: #{referenced_path} " \
94
- "(referenced from #{file})"
95
-
96
- next Regexp.last_match(0)
97
- end
71
+ replaced = content.gsub(/^([ \t]*)##\{([^}]+)\}[ \t]*$/) do
72
+ indentation = Regexp.last_match(1)
73
+ referenced_file = Regexp.last_match(2)
98
74
 
99
- begin
100
- inserted_content = File.binread(referenced_path)
101
- rescue => e
102
- warn "Warning: cannot read #{referenced_path}: #{e.message}"
103
- next Regexp.last_match(0)
104
- end
75
+ referenced_path = File.expand_path(
76
+ referenced_file,
77
+ file_dir
78
+ )
105
79
 
106
- inserted_content = inserted_content.force_encoding(
107
- Encoding::UTF_8
108
- )
80
+ unless File.file?(referenced_path)
81
+ warn "Warning: file not found: #{referenced_path} (referenced from #{file})"
82
+ next Regexp.last_match(0)
83
+ end
109
84
 
110
- unless inserted_content.valid_encoding?
111
- warn "Warning: referenced file is not valid UTF-8: " \
112
- "#{referenced_path}"
85
+ inserted_content = File.read(referenced_path).chomp
113
86
 
114
- next Regexp.last_match(0)
87
+ # Apply the indentation of ##{...}
88
+ # to every non-empty line.
89
+ inserted_content.lines.map do |line|
90
+ if line.strip.empty?
91
+ line
92
+ else
93
+ indentation + line
115
94
  end
95
+ end.join
96
+ end
116
97
 
117
- inserted_content = inserted_content.chomp
118
-
119
- # Apply the indentation from ##{...}
120
- # to every non-empty line.
121
- inserted_content.lines.map do |line|
122
- if line.strip.empty?
123
- line
124
- else
125
- indentation + line
126
- end
127
- end.join
128
- end
129
-
130
- next if replaced == text
131
-
132
- File.binwrite(file, replaced)
98
+ next if replaced == content
133
99
 
134
- puts "Updated: #{file}"
135
- rescue ArgumentError => e
136
- warn "Warning: cannot process #{file}: #{e.message}"
137
- rescue => e
138
- warn "Warning: cannot process #{file}: #{e.message}"
139
- end
100
+ File.write(file, replaced)
101
+ puts "Updated: #{file}"
140
102
  end
141
103
 
142
104
  File.write(
data/moonshard.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "moonshard"
3
- spec.version = "0.2.0"
3
+ spec.version = "0.4.0"
4
4
  spec.authors = ["Tommy Jeff"]
5
5
  spec.email = ["threcius@gmail.com"]
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moonshard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy Jeff