jeanny 0.86 → 0.87

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 (3) hide show
  1. data/lib/jeanny/extend.rb +1 -1
  2. data/lib/jeanny/sugar.rb +49 -20
  3. metadata +2 -2
data/lib/jeanny/extend.rb CHANGED
@@ -32,7 +32,7 @@ class File
32
32
  # Метод для сохранения файла
33
33
  def self.save_file file, data, prefix = ''
34
34
  # Если префикс не пустой, добавляем его к имени файла
35
- file = "#{dirname(expand_path(file))}/#{prefix}#{basename(file)}" unless prefix.empty?
35
+ file = "#{dirname(expand_path(file))}/#{prefix}#{basename(file)}" unless prefix.nil? or prefix.empty?
36
36
  # Открываем файл
37
37
  open(file, 'w') do |file|
38
38
  # Помещаем данные
data/lib/jeanny/sugar.rb CHANGED
@@ -53,27 +53,45 @@ module Jeanny
53
53
  saved_classes = []
54
54
 
55
55
  begin
56
- # Открываем файл
57
- raw_file = File.open_file @compare_file
58
- raw_data = raw_file.split "\n"
59
-
60
- # ... и читаем структиуру
61
- raw_data.map do |line|
62
- line.split(':').map do |hash|
63
- hash.strip
64
- end
65
- end.each_with_index do |item, index|
66
- if item.length != 2 or item[1].empty?
67
- fail JeannyCompareFileFormatError, "Какая то ерунда с одим (а может больше) классом. Можно пропустить, но хрен его знает что дальше будет…\n" + "файл: #{file}, строка: #{index}\n#{raw_data[index]}".red
68
- else
56
+ meat = File.open File.expand_path(@compare_file)
57
+ meat.read.gsub(/\s+|\'/, '').gsub(/^.*\{|\}.*$/, '').split(',').each do |item|
58
+ item = item.split('=>').delete_if { |x| x.nil? or x.empty? }
59
+ if item.length.eql? 2
69
60
  saved_classes << [item[0], item[1]]
61
+ else
62
+ fail JeannyCompareFileFormatError, "Какая то ерунда с одим (а может больше) классом. Можно пропустить, но хрен его знает что дальше будет…\n" + "файл: #{file}, строка: #{index}\n#{raw_data[index]}".red
70
63
  end
71
64
  end
65
+
66
+ # p saved_classes
67
+
72
68
  rescue Exception => e
73
69
  $stderr.puts e.message
74
- exit 1
70
+ exit 1
75
71
  end
76
72
 
73
+ # begin
74
+ # # Открываем файл
75
+ # raw_file = File.open_file @compare_file
76
+ # raw_data = raw_file.split "\n"
77
+ #
78
+ # # ... и читаем структиуру
79
+ # raw_data.map do |line|
80
+ # line.split(':').map do |hash|
81
+ # hash.strip
82
+ # end
83
+ # end.each_with_index do |item, index|
84
+ # if item.length != 2 or item[1].empty?
85
+ # fail JeannyCompareFileFormatError, "Какая то ерунда с одим (а может больше) классом. Можно пропустить, но хрен его знает что дальше будет…\n" + "файл: #{file}, строка: #{index}\n#{raw_data[index]}".red
86
+ # else
87
+ # saved_classes << [item[0], item[1]]
88
+ # end
89
+ # end
90
+ # rescue Exception => e
91
+ # $stderr.puts e.message
92
+ # exit 1
93
+ # end
94
+
77
95
  # Сравниваем
78
96
  new_classes = @engine.compare_with saved_classes
79
97
 
@@ -93,12 +111,25 @@ module Jeanny
93
111
  fail RuntimeError, 'на данном этапе нельзя вызывать сохранение классов' unless canbe[:save]
94
112
 
95
113
  file = file.empty? ? @compare_file : file
114
+ temp = <<CODE
115
+ [%
116
+ classes =
117
+ {
118
+ %classes%
119
+ }
120
+ %]
121
+ CODE
96
122
 
97
123
  File.open(File.expand_path(file), 'w') do |f|
124
+
125
+ classes = []
98
126
  @engine.classes.each do |key, val|
99
- f.puts "#{key}: #{val.rjust(40 - key.length)}"
100
- end
101
- end unless @compare_file.empty? and file.empty?
127
+ classes << " " * 20 + "'#{key}'" + " => '#{val}'".rjust(50 - key.length)
128
+ end
129
+
130
+ f.puts temp.gsub /%classes%/, classes.join(",\n")
131
+
132
+ end unless file.nil? or file.empty?
102
133
 
103
134
  end
104
135
 
@@ -163,7 +194,7 @@ module Jeanny
163
194
  data = File.open_file file
164
195
  data = @engine.replace data, type
165
196
 
166
- File.save_file file, data
197
+ File.save_file file, data, replace[:prefix]
167
198
 
168
199
  rescue Exception => e
169
200
  puts e.message + "\n#{$@}"
@@ -175,8 +206,6 @@ module Jeanny
175
206
 
176
207
  end
177
208
 
178
-
179
-
180
209
  def replace args = { }
181
210
 
182
211
  fail "We can`t replace here..." unless @canbe[:replace]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeanny
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.86"
4
+ version: "0.87"
5
5
  platform: ruby
6
6
  authors:
7
7
  - gfranco
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-05 00:00:00 +03:00
12
+ date: 2009-10-26 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies: []
15
15