immosquare-yaml 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 573eadd9feb826e6365b2a86d74f224315a4cf04fae6636be0259587f4701da6
4
- data.tar.gz: a8fe5672e271f2cf620a4d1f6091a4a3eb1be22dc8713b95568ed79c4d7b5927
3
+ metadata.gz: 8e9284e5c8a302af2d5c35d6a88ec0bbaea401be34629800f585347a9ad0de22
4
+ data.tar.gz: f9e2da6ee693fe3e001eaa6ec9d233bca746c805b2eaabacecc9152d4fe7e781
5
5
  SHA512:
6
- metadata.gz: 5ef47496ea01d662155006e97039e951b47fc601d1ec803293240b574e317f1e45821c2aa9e8c5e4baeb3a36ab8bd9ecbe362f4142a8cefb1718b1356e6af366
7
- data.tar.gz: 766fc004a23ee4bc5bc6893492242d8029fa866faa1aa840963af12c1c49f26a2c8323e8805bf23aca68e3f3d716d7f6bbcd3206ea007eb867a073ba799aa980
6
+ metadata.gz: 523ee5214b2a8bef47ddad6f94c2035cc84eef36d2312a144b07757546f9487d7baeb2c88ecbd0e1558fc3571ec7c868f40518e214fd80b59320bf505c829293
7
+ data.tar.gz: 980155dbb44f8bba350c060b20d64f3cb0106f2d84d374b7aa6953ace6df467cdbb5db539830e9b93f1762b5d34c69ca28abecc7ba327dc3bb6c011056615439
@@ -28,18 +28,5 @@ module ImmosquareYaml
28
28
  end
29
29
  end
30
30
  end
31
-
32
- ##============================================================##
33
- ## sort_by_key Function
34
- ## Purpose: Sort a hash by its keys, optionally recursively, with
35
- ## case-insensitive comparison and stripping of double quotes.
36
- ## ============================================================ #
37
- def sort_by_key(hash, recursive = false, &block)
38
- block ||= proc {|a, b| a.to_s.downcase.gsub("\"", "") <=> b.to_s.downcase.gsub("\"", "") }
39
- hash.keys.sort(&block).each_with_object({}) do |key, seed|
40
- seed[key] = hash[key]
41
- seed[key] = sort_by_key(seed[key], true, &block) if recursive && seed[key].is_a?(Hash)
42
- end
43
- end
44
31
  end
45
32
  end
@@ -1,3 +1,3 @@
1
1
  module ImmosquareYaml
2
- VERSION = "0.1.12".freeze
2
+ VERSION = "0.1.13".freeze
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "English"
2
+ require "immosquare-extensions"
2
3
  require_relative "immosquare-yaml/configuration"
3
4
  require_relative "immosquare-yaml/shared_methods"
4
5
  require_relative "immosquare-yaml/translate"
@@ -54,6 +55,7 @@ module ImmosquareYaml
54
55
  }.merge(options)
55
56
 
56
57
  begin
58
+ output_file_path = nil
57
59
  raise("File not found") if !File.exist?(file_path)
58
60
 
59
61
  ##===========================================================================##
@@ -73,7 +75,7 @@ module ImmosquareYaml
73
75
  ##===========================================================================##
74
76
  clean_yml(file_path)
75
77
  parsed_yml = parse(file_path)
76
- parsed_yml = sort_by_key(parsed_yml, options[:sort])
78
+ parsed_yml = parsed_yml.sort_by_key(true)
77
79
  parsed_yml = dump(parsed_yml)
78
80
 
79
81
  ##===========================================================================##
@@ -88,7 +90,12 @@ module ImmosquareYaml
88
90
  File.write(output_file_path, parsed_yml)
89
91
  true
90
92
  rescue StandardError => e
93
+ ##===========================================================================##
94
+ ## Restore original content if necessary
95
+ ##===========================================================================##
96
+ File.write(file_path, original_content) if output_file_path != file_path && !original_content.nil?
91
97
  puts(e.message)
98
+ puts(e.backtrace)
92
99
  false
93
100
  end
94
101
  end
@@ -110,6 +117,7 @@ module ImmosquareYaml
110
117
  options = {:sort => true}.merge(options)
111
118
 
112
119
  begin
120
+ original_content = nil
113
121
  raise("File not found") if !File.exist?(file_path)
114
122
 
115
123
  ##===========================================================================##
@@ -118,22 +126,30 @@ module ImmosquareYaml
118
126
  original_content = File.read(file_path)
119
127
 
120
128
  ##===========================================================================##
121
- ## clean, parse & Sort
129
+ ## clean the file
122
130
  ##===========================================================================##
123
131
  clean_yml(file_path)
132
+
133
+ ##===========================================================================##
134
+ ## parse the file & sort if necessary
135
+ ##===========================================================================##
124
136
  parsed_xml = parse_xml(file_path)
125
- parsed_xml = sort_by_key(parsed_xml, options[:sort]) if options[:sort]
137
+ parsed_xml = parsed_xml.sort_by_key(true) if options[:sort]
126
138
 
127
139
  ##===========================================================================##
128
140
  ## Restore original content
129
141
  ##===========================================================================##
130
- File.write(file_path, original_content)
142
+ File.write(file_path, original_content) if !original_content.nil?
131
143
 
132
144
  ##===========================================================================##
133
145
  ## Return the parsed YAML file
134
146
  ##===========================================================================##
135
147
  parsed_xml
136
148
  rescue StandardError => e
149
+ ##===========================================================================##
150
+ ## Restore original content
151
+ ##===========================================================================##
152
+ File.write(file_path, original_content) if !original_content.nil?
137
153
  puts(e.message)
138
154
  false
139
155
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - IMMO SQUARE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-29 00:00:00.000000000 Z
11
+ date: 2023-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iso-639
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: immosquare-extensions
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: IMMOSQUARE-YAML is a specialized Ruby gem tailored primarily for parsing
42
56
  and dumping YML translation files, addressing challenges faced with other parsers
43
57
  like interpreting translation keys as booleans, multi-line strings, and more.