riel 1.2.0 → 1.2.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: d9fec4fdc968d7eac63fc2e894a6bd3b2252d86f
4
- data.tar.gz: 38b6c94c7045866f8fbf88fdd6ec7861a0bd0750
3
+ metadata.gz: 556377e46b194e614f127b38aed69a4a219c7649
4
+ data.tar.gz: f8dcbbd034dca93cd8951c472b6a08a0f01921a4
5
5
  SHA512:
6
- metadata.gz: 59546acde4a6fdf7d2716be86af60d2cc6c5a3a6fa389dede2790de02c2c251f6708510f59413c07c6f79604529c8c957cd4a5e48250f1007ecf3cae9740a10f
7
- data.tar.gz: a2d02521a496858feb6d9d08dfb2fca21ec6bf7f97c9b381ef971554ad49a8c8bf9ec6f30ebeb1d0106e557b04a474a4b1c544ce928ea94b251810c44cb432f2
6
+ metadata.gz: '08816409b9098824794181fbb0169bca37ea211e0da34cc5d052d02a6ed34b37284bb3c9932c0440dfcf1a36a95ce36d2c2c287b4f56126dbfb43417ed58808b'
7
+ data.tar.gz: 2af4733c75275ceb397aa619269846a51bde309f568177d62a6560c83aaeb331747cfd91d7e229027b516d7fe3c68afc72c520a3f5952c77859c79f2b1ba06e5
@@ -121,7 +121,7 @@ class FileType
121
121
  end
122
122
 
123
123
  def text? file
124
- return false unless File.exists?(file)
124
+ return false unless File.exist?(file)
125
125
 
126
126
  if md = EXTENSION_REGEXP.match(file.to_s)
127
127
  suffix = md[1]
@@ -1,31 +1,36 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- # Represents a resource file, where '#' is used to comment to end of lines, and
5
- # name/value pairs are separated by '=' or ':'.
4
+ # Represents a resource file, where '#' is used to comment to end of lines, and name/value pairs are
5
+ # separated by '=' or ':'.
6
6
 
7
7
  class RCFile
8
8
  attr_reader :settings
9
9
 
10
- # Reads the RC file, if it exists, and if a block is passed, calls the block
11
- # with each name/value pair, which are also accessible via
12
- # <code>settings</code>.
10
+ # Reads the RC file, if it exists, and if a block is passed, calls the block with each name/value
11
+ # pair, which are also accessible via <code>settings</code>.
13
12
 
14
- def initialize(fname, &blk)
13
+ def initialize args = Hash.new, &blk
15
14
  @settings = Array.new
15
+
16
+ unless lines = args[:lines]
17
+ if fname = args[:filename]
18
+ lines = IO::readlines fname
19
+ end
20
+ end
21
+
22
+ cmtre = Regexp.new '\s*#.*'
23
+ nvre = Regexp.new '\s*[=:]\s*'
16
24
 
17
- if File.exists? fname
18
- IO::readlines(fname).each do |line|
19
- line.sub!(/\s*#.*/, "")
20
- line.chomp!
21
- name, value = line.split(/\s*[=:]\s*/)
22
- if name && value
23
- name.strip!
24
- value.strip!
25
- @settings << [ name, value ]
26
- if blk
27
- blk.call name, value
28
- end
25
+ lines.each do |line|
26
+ line.sub! cmtre, ''
27
+ name, value = line.split nvre
28
+ if name && value
29
+ name.strip!
30
+ value.strip!
31
+ @settings << [ name, value ]
32
+ if blk
33
+ blk.call name, value
29
34
  end
30
35
  end
31
36
  end
@@ -3,36 +3,40 @@
3
3
 
4
4
  require 'test/unit'
5
5
  require 'riel/rcfile'
6
- require 'riel/tempfile'
6
+ require 'paramesan'
7
7
 
8
8
  class RCFileTestCase < Test::Unit::TestCase
9
- def test_simple
10
- separators = %w{ = : }
11
- leading_spaces = [ "", " ", " " ]
12
- trailing_spaces = leading_spaces.dup
13
- comments = [ "", "# a comment" ]
14
-
15
- num = 0
16
- tempfile = Tempfile.open("rcfile_test") do |tf|
17
- tf.puts "# this is a comment"
18
- tf.puts ""
19
-
20
- separators.each do |sep|
21
- leading_spaces.each do |lsp|
22
- trailing_spaces.each do |tsp|
23
- comments.each do |cmt|
24
- tf.puts "#{lsp}name#{num}#{sep}value#{num}#{tsp}#{cmt}"
25
- num += 1
26
- end
27
- end
28
- end
9
+ include Paramesan
10
+
11
+ def self.build_params
12
+ kv = [ "k", "v" ]
13
+ kvary = [ kv ]
14
+
15
+ Array.new.tap do |params|
16
+ params << [ Array.new, Array.new ]
17
+ params << [ Array.new, [ "" ] ]
18
+ [ "k:v", "k: v", "k :v", "k=v", "k= v", "k =v", "k:v ", " k:v" ].each do |line|
19
+ params << [ kvary, [ line ] ]
29
20
  end
21
+ params << [ kvary, [ "", "k:v" ] ]
22
+ params << [ kvary, [ "# comment", "k:v" ] ]
23
+ params << [ kvary, [ " # comment", "k:v" ] ]
24
+ params << [ Array.new, [ "k:#v" ] ]
25
+ params << [ [ [ "k", "v" ] ], [ "k:v#x" ] ]
26
+ params << [ [ [ "k", "v" ], [ "k2", "v2" ] ], [ "k:v", "k2:v2" ] ]
30
27
  end
31
-
32
- rc = RCFile.new tempfile
33
- (0 ... num).each do |i|
34
- assert_not_nil rc.settings[i]
35
- assert_equal [ "name#{i}", "value#{i}" ], rc.settings[i]
28
+ end
29
+
30
+ param_test build_params do |exp, lines|
31
+ rc = RCFile.new lines: lines
32
+ assert_equal exp, rc.settings, "lines: #{lines}"
33
+ end
34
+
35
+ def test_block
36
+ called = Array.new
37
+ RCFile.new(lines: [ "k:v" ]) do |key, value|
38
+ called << [ key, value ]
36
39
  end
40
+ assert_equal [ [ "k", "v" ] ], called
37
41
  end
38
42
  end
@@ -22,7 +22,7 @@ class RegexpTestCase < Test::Unit::TestCase
22
22
 
23
23
  def test_invalid_whole_word
24
24
  assert_raises(RuntimeError) do
25
- re = Regexp.create ':abc', wholewords: true
25
+ Regexp.create ':abc', wholewords: true
26
26
  end
27
27
  end
28
28
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Pace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-20 00:00:00.000000000 Z
11
+ date: 2017-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.1.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: paramesan
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: This library extends the core Ruby libraries.
28
42
  email: jeugenepace@gmail.com
29
43
  executables: []
@@ -31,6 +45,7 @@ extensions: []
31
45
  extra_rdoc_files:
32
46
  - README.md
33
47
  files:
48
+ - README.md
34
49
  - lib/riel.rb
35
50
  - lib/riel/command.rb
36
51
  - lib/riel/date.rb
@@ -71,8 +86,7 @@ files:
71
86
  - test/riel/string_test.rb
72
87
  - test/riel/tempfile_test.rb
73
88
  - test/riel/timer_test.rb
74
- - README.md
75
- homepage: http://www.incava.org/projects/riel
89
+ homepage: http://www.github.com/jpace/riel
76
90
  licenses: []
77
91
  metadata: {}
78
92
  post_install_message:
@@ -81,17 +95,17 @@ require_paths:
81
95
  - lib
82
96
  required_ruby_version: !ruby/object:Gem::Requirement
83
97
  requirements:
84
- - - '>='
98
+ - - ">="
85
99
  - !ruby/object:Gem::Version
86
100
  version: '0'
87
101
  required_rubygems_version: !ruby/object:Gem::Requirement
88
102
  requirements:
89
- - - '>='
103
+ - - ">="
90
104
  - !ruby/object:Gem::Version
91
105
  version: '0'
92
106
  requirements: []
93
107
  rubyforge_project:
94
- rubygems_version: 2.0.6
108
+ rubygems_version: 2.6.3
95
109
  signing_key:
96
110
  specification_version: 4
97
111
  summary: Extensions to core Ruby code.