raph 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +16 -16
- data/.travis.yml +9 -9
- data/.yardopts +2 -0
- data/Gemfile +4 -4
- data/LICENSE +202 -202
- data/LICENSE.txt +22 -22
- data/README.md +103 -109
- data/Rakefile +6 -6
- data/example/sample.rb +6 -6
- data/lib/raph.rb +61 -61
- data/lib/raph/parser/assignment_parser.rb +38 -33
- data/lib/raph/parser/base_parser.rb +50 -47
- data/lib/raph/parser/file_parser.rb +24 -24
- data/lib/raph/parser/flag_parser.rb +31 -31
- data/lib/raph/version.rb +3 -3
- data/raph.gemspec +29 -26
- data/spec/raph/parser/assinment_parser_spec.rb +45 -46
- data/spec/raph/parser/base_parser_spec.rb +47 -47
- data/spec/raph/parser/file_parser_spec.rb +25 -25
- data/spec/raph/parser/flag_parser_spec.rb +48 -48
- data/spec/raph_spec.rb +56 -56
- data/spec/spec_helper.rb +1 -1
- metadata +17 -15
@@ -1,25 +1,25 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'raph/parser/file_parser'
|
4
|
-
|
5
|
-
module Raph
|
6
|
-
module Parser
|
7
|
-
describe FileParser do
|
8
|
-
describe '#parse' do
|
9
|
-
it 'detects files' do
|
10
|
-
expect(subject.parse(['**/*.rb'])).to include(Dir["**/file_parser_spec.rb"].join)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'does not detect non files' do
|
14
|
-
expect(subject.parse(['no-such-file.py'])).to be_empty
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#id' do
|
19
|
-
it 'has correct form' do
|
20
|
-
expect(subject.id).to eql :files
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'raph/parser/file_parser'
|
4
|
+
|
5
|
+
module Raph
|
6
|
+
module Parser
|
7
|
+
describe FileParser do
|
8
|
+
describe '#parse' do
|
9
|
+
it 'detects files' do
|
10
|
+
expect(subject.parse(['**/*.rb'])).to include(Dir["**/file_parser_spec.rb"].join)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'does not detect non files' do
|
14
|
+
expect(subject.parse(['no-such-file.py'])).to be_empty
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#id' do
|
19
|
+
it 'has correct form' do
|
20
|
+
expect(subject.id).to eql :files
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,48 +1,48 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Raph
|
4
|
-
module Parser
|
5
|
-
describe FlagParser do
|
6
|
-
describe '#id' do
|
7
|
-
it 'has correct form' do
|
8
|
-
expect(subject.id).to eq :flags
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#parse' do
|
13
|
-
it 'returns flags only' do
|
14
|
-
expect(subject.parse(['-h', '-9', '123', '--config', 'config.xml'])).
|
15
|
-
to match_array([
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'has no flags here' do
|
19
|
-
expect(subject.parse(['true', '-', '123'])).to match_array([])
|
20
|
-
expect(subject.parse([])).to match_array([])
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#flag?' do
|
25
|
-
def flag?(option)
|
26
|
-
!subject.flag?(option).nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'is a flag' do
|
30
|
-
expect(flag? '-h').to be true
|
31
|
-
expect(flag? '-T').to be true
|
32
|
-
expect(flag? '--config').to be true
|
33
|
-
expect(flag? '--my-flag').to be true
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'is not a flag?' do
|
37
|
-
expect(flag? '').to be false
|
38
|
-
expect(flag? '-').to be false
|
39
|
-
expect(flag? '--').to be false
|
40
|
-
expect(flag? '---').to be false
|
41
|
-
expect(flag? '--h').to be false
|
42
|
-
expect(flag? 'option').to be false
|
43
|
-
expect(flag? '---option').to be false
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Raph
|
4
|
+
module Parser
|
5
|
+
describe FlagParser do
|
6
|
+
describe '#id' do
|
7
|
+
it 'has correct form' do
|
8
|
+
expect(subject.id).to eq :flags
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#parse' do
|
13
|
+
it 'returns flags only' do
|
14
|
+
expect(subject.parse(['-h', '-9', '123', '--config', 'config.xml'])).
|
15
|
+
to match_array([:h, :'9', :config])
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has no flags here' do
|
19
|
+
expect(subject.parse(['true', '-', '123'])).to match_array([])
|
20
|
+
expect(subject.parse([])).to match_array([])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#flag?' do
|
25
|
+
def flag?(option)
|
26
|
+
!subject.flag?(option).nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'is a flag' do
|
30
|
+
expect(flag? '-h').to be true
|
31
|
+
expect(flag? '-T').to be true
|
32
|
+
expect(flag? '--config').to be true
|
33
|
+
expect(flag? '--my-flag').to be true
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'is not a flag?' do
|
37
|
+
expect(flag? '').to be false
|
38
|
+
expect(flag? '-').to be false
|
39
|
+
expect(flag? '--').to be false
|
40
|
+
expect(flag? '---').to be false
|
41
|
+
expect(flag? '--h').to be false
|
42
|
+
expect(flag? 'option').to be false
|
43
|
+
expect(flag? '---option').to be false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/raph_spec.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module Raph
|
5
|
-
describe Raph do
|
6
|
-
|
7
|
-
class NumberParser
|
8
|
-
attr_accessor :id, :max
|
9
|
-
|
10
|
-
def initialize(id, max=100)
|
11
|
-
@id = id
|
12
|
-
@max = max
|
13
|
-
end
|
14
|
-
|
15
|
-
def parse(args)
|
16
|
-
args.select { |x| x <= max }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#parse' do
|
21
|
-
let (:numbers) { (1..100) }
|
22
|
-
let (:parser1) { NumberParser.new(:first, 5) }
|
23
|
-
let (:parser2) { NumberParser.new(:second, 6) }
|
24
|
-
|
25
|
-
it 'should parse nothing if parsers not added' do
|
26
|
-
raph = Raph.new.tap { |r| r.parse numbers }
|
27
|
-
expect(raph.all).to match_array numbers
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should have correspoding attribute if parser added' do
|
31
|
-
raph = Raph.new.tap do |r|
|
32
|
-
r.add_parser(parser1)
|
33
|
-
r.add_parser(parser2)
|
34
|
-
r.parse(numbers)
|
35
|
-
end
|
36
|
-
expect(raph.all).to match_array numbers
|
37
|
-
expect(raph.send(parser1.id)).to match_array (1..parser1.max)
|
38
|
-
expect(raph.send(parser2.id)).to match_array (1..parser2.max)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'when we include Raph' do
|
44
|
-
it 'loads global variable' do
|
45
|
-
expect($raph).to be_a Raph
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'has proper attributes' do
|
49
|
-
raph = $raph
|
50
|
-
expect(raph.all).not_to be nil
|
51
|
-
expect(raph.send(FlagParser.new.id)).not_to be nil
|
52
|
-
expect(raph.send(FileParser.new.id)).not_to be nil
|
53
|
-
expect(raph.send(AssignmentParser.new.id)).not_to be nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Raph
|
5
|
+
describe Raph do
|
6
|
+
|
7
|
+
class NumberParser
|
8
|
+
attr_accessor :id, :max
|
9
|
+
|
10
|
+
def initialize(id, max=100)
|
11
|
+
@id = id
|
12
|
+
@max = max
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse(args)
|
16
|
+
args.select { |x| x <= max }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#parse' do
|
21
|
+
let (:numbers) { (1..100) }
|
22
|
+
let (:parser1) { NumberParser.new(:first, 5) }
|
23
|
+
let (:parser2) { NumberParser.new(:second, 6) }
|
24
|
+
|
25
|
+
it 'should parse nothing if parsers not added' do
|
26
|
+
raph = Raph.new.tap { |r| r.parse numbers }
|
27
|
+
expect(raph.all).to match_array numbers
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should have correspoding attribute if parser added' do
|
31
|
+
raph = Raph.new.tap do |r|
|
32
|
+
r.add_parser(parser1)
|
33
|
+
r.add_parser(parser2)
|
34
|
+
r.parse(numbers)
|
35
|
+
end
|
36
|
+
expect(raph.all).to match_array numbers
|
37
|
+
expect(raph.send(parser1.id)).to match_array (1..parser1.max)
|
38
|
+
expect(raph.send(parser2.id)).to match_array (1..parser2.max)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when we include Raph' do
|
44
|
+
it 'loads global variable' do
|
45
|
+
expect($raph).to be_a Raph
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'has proper attributes' do
|
49
|
+
raph = $raph
|
50
|
+
expect(raph.all).not_to be nil
|
51
|
+
expect(raph.send(FlagParser.new.id)).not_to be nil
|
52
|
+
expect(raph.send(FileParser.new.id)).not_to be nil
|
53
|
+
expect(raph.send(AssignmentParser.new.id)).not_to be nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'raph'
|
1
|
+
require 'raph'
|
metadata
CHANGED
@@ -1,66 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitalii Elenhaupt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
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.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description:
|
55
|
+
description: |2
|
56
|
+
Lightweight argument parsing with flexible structure.
|
57
|
+
Add your parser in few minutes.
|
56
58
|
email:
|
57
59
|
- velenhaupt@gmail.com
|
58
60
|
executables: []
|
59
61
|
extensions: []
|
60
62
|
extra_rdoc_files: []
|
61
63
|
files:
|
62
|
-
-
|
63
|
-
-
|
64
|
+
- .gitignore
|
65
|
+
- .travis.yml
|
66
|
+
- .yardopts
|
64
67
|
- Gemfile
|
65
68
|
- LICENSE
|
66
69
|
- LICENSE.txt
|
@@ -90,17 +93,17 @@ require_paths:
|
|
90
93
|
- lib
|
91
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
92
95
|
requirements:
|
93
|
-
- -
|
96
|
+
- - '>='
|
94
97
|
- !ruby/object:Gem::Version
|
95
98
|
version: 1.9.3
|
96
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
100
|
requirements:
|
98
|
-
- -
|
101
|
+
- - '>='
|
99
102
|
- !ruby/object:Gem::Version
|
100
103
|
version: '0'
|
101
104
|
requirements: []
|
102
105
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.0.14
|
104
107
|
signing_key:
|
105
108
|
specification_version: 4
|
106
109
|
summary: Ruby Argument Parsing for Humans.
|
@@ -111,4 +114,3 @@ test_files:
|
|
111
114
|
- spec/raph/parser/flag_parser_spec.rb
|
112
115
|
- spec/raph_spec.rb
|
113
116
|
- spec/spec_helper.rb
|
114
|
-
has_rdoc:
|