ext 1.1.3 → 2.1.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.
@@ -3,7 +3,6 @@ module Externals
3
3
  SECTION_TITLE_REGEX_NO_GROUPS = /^\s*\[(?:[^\]]*)\]\s*$/
4
4
  SECTION_TITLE_REGEX = /^\s*\[([^\]]*)\]\s*$/
5
5
 
6
-
7
6
  class Section
8
7
  attr_accessor :title_string, :body_string, :title, :rows
9
8
 
@@ -15,12 +14,11 @@ module Externals
15
14
 
16
15
  raise "Invalid section title: #{title_string}" unless title
17
16
 
18
- self.rows = body_string.strip.split(/\n/)
17
+ self.rows = body_string.strip.split("\n")
19
18
  end
20
19
 
21
-
22
- SETTING_REGEX = /^\s*([\.\w-]+)\s*=\s*([^#\n]*)(?:#[^\n]*)?$/
23
- SET_SETTING_REGEX = /^(\s*(?:[\.\w-]+)\s*=\s*)(?:[^#\n]*)(#[^\n]*)?$/
20
+ SETTING_REGEX = /^\s*([.\w-]+)\s*=\s*([^#\n]*)(?:#[^\n]*)?$/
21
+ SET_SETTING_REGEX = /^(\s*(?:[.\w-]+)\s*=\s*)(?:[^#\n]*)(#[^\n]*)?$/
24
22
 
25
23
  def attributes
26
24
  retval = {}
@@ -31,6 +29,7 @@ module Externals
31
29
  end
32
30
  retval
33
31
  end
32
+
34
33
  def setting key
35
34
  rows.each do |row|
36
35
  if row =~ SETTING_REGEX && key.to_s == $1
@@ -39,6 +38,7 @@ module Externals
39
38
  end
40
39
  nil
41
40
  end
41
+
42
42
  def set_setting key, value
43
43
  key = key.to_s
44
44
  found = nil
@@ -46,18 +46,23 @@ module Externals
46
46
  rows.each_with_index do |row, index|
47
47
  if row =~ SETTING_REGEX && key == $1
48
48
  raise "found #{key} twice!" if found
49
+
49
50
  found = index
50
51
  end
51
52
  end
52
53
 
53
54
  if found
54
55
  if rows[found] !~ SET_SETTING_REGEX
56
+ # simplecov:disable
55
57
  raise "thought I found the row, but didn't"
58
+ # simplecov:enable
56
59
  end
60
+
57
61
  rows[found] = "#{$1}#{value}#{$2}"
58
62
  else
59
63
  rows << "#{key} = #{value}"
60
64
  end
65
+
61
66
  value
62
67
  end
63
68
 
@@ -69,6 +74,7 @@ module Externals
69
74
  rows.each_with_index do |row, index|
70
75
  if row =~ SETTING_REGEX && key == $1
71
76
  raise "found #{key} twice!" if found
77
+
72
78
  found = index
73
79
  end
74
80
  end
@@ -76,8 +82,11 @@ module Externals
76
82
  if found
77
83
  value = self[key]
78
84
  if rows[found] !~ SET_SETTING_REGEX
85
+ # simplecov:disable
79
86
  raise "thought I found the row, but didn't"
87
+ # simplecov:enable
80
88
  end
89
+
81
90
  rows.delete rows[found]
82
91
  end
83
92
  value
@@ -86,17 +95,11 @@ module Externals
86
95
  def [] key
87
96
  setting(key)
88
97
  end
98
+
89
99
  def []= key, value
90
100
  set_setting(key, value)
91
101
  end
92
102
 
93
- def add_row(row)
94
- rows << row
95
-
96
- self.body_string = body_string.chomp + "\n#{row}\n"
97
- #clear_caches
98
- end
99
-
100
103
  def to_s
101
104
  "[#{title}]\n#{rows.join("\n")}"
102
105
  end
@@ -117,7 +120,7 @@ module Externals
117
120
  def []= title, hash
118
121
  add_empty_section title
119
122
  section = self[title]
120
- hash.each_pair do |key,value|
123
+ hash.each_pair do |key, value|
121
124
  section[key] = value
122
125
  end
123
126
  end
@@ -126,12 +129,14 @@ module Externals
126
129
  sec = sections.detect{|section| section.title == sec}
127
130
 
128
131
  raise "No section found in config file for #{sec}" unless sec
132
+
129
133
  sections.delete(sec)
130
134
  end
131
135
 
132
- def add_empty_section title
136
+ def add_empty_section title
133
137
  raise "Section already exists" if self[title]
134
- sections << Section.new("[#{title.to_s}]", "")
138
+
139
+ sections << Section.new("[#{title}]", "")
135
140
  end
136
141
 
137
142
  def removed_project_paths other_config
@@ -156,12 +161,14 @@ module Externals
156
161
  file_string.each_line {|line| titles << line if line =~ SECTION_TITLE_REGEX}
157
162
  bodies = file_string.split SECTION_TITLE_REGEX_NO_GROUPS
158
163
 
159
- if titles.size > 0 && bodies.size > 0
164
+ if !titles.empty? && !bodies.empty?
160
165
  if titles.size + 1 != bodies.size
166
+ # simplecov:disable
161
167
  raise "bodies and sections do not match up"
168
+ # simplecov:enable
162
169
  end
163
170
 
164
- bodies = bodies[1..(bodies.size - 1)]
171
+ bodies = bodies[1..]
165
172
 
166
173
  (0...(bodies.size)).each do |index|
167
174
  sections << Section.new(titles[index], bodies[index])
@@ -171,13 +178,12 @@ module Externals
171
178
 
172
179
  def write path = ".externals"
173
180
  raise "no path given" unless path
174
- open(path, 'w') do |f|
175
- f.write to_s
176
- end
181
+
182
+ File.write(path, to_s)
177
183
  end
178
184
 
179
185
  def to_s
180
- sections.map(&:to_s).join("\n\n")
186
+ sections.join("\n\n")
181
187
  end
182
188
  end
183
189
  end