selector 0.0.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.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +9 -0
  4. data/.metrics +9 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +2 -0
  7. data/.travis.yml +20 -0
  8. data/.yardopts +3 -0
  9. data/CHANGELOG.md +5 -0
  10. data/Gemfile +7 -0
  11. data/Guardfile +14 -0
  12. data/LICENSE +21 -0
  13. data/README.md +147 -0
  14. data/Rakefile +27 -0
  15. data/config/metrics/STYLEGUIDE +230 -0
  16. data/config/metrics/cane.yml +5 -0
  17. data/config/metrics/churn.yml +6 -0
  18. data/config/metrics/flay.yml +2 -0
  19. data/config/metrics/metric_fu.yml +14 -0
  20. data/config/metrics/reek.yml +1 -0
  21. data/config/metrics/roodi.yml +24 -0
  22. data/config/metrics/rubocop.yml +72 -0
  23. data/config/metrics/saikuro.yml +3 -0
  24. data/config/metrics/simplecov.yml +6 -0
  25. data/config/metrics/yardstick.yml +37 -0
  26. data/lib/selector.rb +55 -0
  27. data/lib/selector/and.rb +64 -0
  28. data/lib/selector/anything.rb +30 -0
  29. data/lib/selector/array.rb +42 -0
  30. data/lib/selector/collection.rb +37 -0
  31. data/lib/selector/condition.rb +99 -0
  32. data/lib/selector/function.rb +36 -0
  33. data/lib/selector/not.rb +50 -0
  34. data/lib/selector/nothing.rb +30 -0
  35. data/lib/selector/or.rb +54 -0
  36. data/lib/selector/regexp.rb +49 -0
  37. data/lib/selector/version.rb +9 -0
  38. data/selector.gemspec +25 -0
  39. data/spec/integration/blacklist_spec.rb +33 -0
  40. data/spec/integration/composition_spec.rb +34 -0
  41. data/spec/integration/negation_spec.rb +13 -0
  42. data/spec/integration/whitelist_spec.rb +33 -0
  43. data/spec/shared/generator.rb +8 -0
  44. data/spec/spec_helper.rb +12 -0
  45. data/spec/unit/selector/and_spec.rb +100 -0
  46. data/spec/unit/selector/anything_spec.rb +29 -0
  47. data/spec/unit/selector/array_spec.rb +76 -0
  48. data/spec/unit/selector/collection_spec.rb +48 -0
  49. data/spec/unit/selector/condition_spec.rb +135 -0
  50. data/spec/unit/selector/function_spec.rb +46 -0
  51. data/spec/unit/selector/not_spec.rb +61 -0
  52. data/spec/unit/selector/nothing_spec.rb +29 -0
  53. data/spec/unit/selector/or_spec.rb +88 -0
  54. data/spec/unit/selector/regexp_spec.rb +69 -0
  55. data/spec/unit/selector_spec.rb +148 -0
  56. metadata +145 -0
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+
3
+ module Selector
4
+
5
+ describe Selector::Regexp do
6
+
7
+ let(:one) { described_class.new(/1\.1/) }
8
+ let(:two) { described_class.new(/2/) }
9
+
10
+ describe ".new" do
11
+
12
+ subject { one }
13
+
14
+ it { is_expected.to be_kind_of Condition }
15
+ it { is_expected.to be_frozen }
16
+
17
+ it "requires exactly 1 argument" do
18
+ expect { described_class.new }.to raise_error ArgumentError
19
+ expect { described_class.new(/1/, /2/) }
20
+ .to raise_error ArgumentError
21
+ end
22
+
23
+ end # describe .new
24
+
25
+ describe "#[]" do
26
+
27
+ subject { one[value] }
28
+
29
+ context "value that matches the regexp" do
30
+
31
+ let(:value) { 1.1 }
32
+ it { is_expected.to eql(true) }
33
+
34
+ end # context
35
+
36
+ context "value that doesn't match the regexp" do
37
+
38
+ let(:value) { 3 }
39
+ it { is_expected.to eql(false) }
40
+
41
+ end # context
42
+
43
+ end # describe #[]
44
+
45
+ describe "#|" do
46
+
47
+ context "regexp" do
48
+
49
+ subject { one | two }
50
+
51
+ it "updates the regexp" do
52
+ expect(subject).to be_kind_of Regexp
53
+ expect(subject.attribute).to eql(/(#{/1\.1/})|(#{/2/})/)
54
+ end
55
+
56
+ end # context
57
+
58
+ context "value that doesn't match the regexp" do
59
+
60
+ subject { one | Condition.new }
61
+ it { is_expected.to be_kind_of(Or) }
62
+
63
+ end # context
64
+
65
+ end # describe #[]
66
+
67
+ end # describe Selector::Regexp
68
+
69
+ end # module Selector
@@ -0,0 +1,148 @@
1
+ # encoding: utf-8
2
+
3
+ module Selector
4
+
5
+ describe Selector do
6
+
7
+ describe "::ANYTHING" do
8
+
9
+ subject { described_class::ANYTHING }
10
+ it { is_expected.to be_kind_of Anything }
11
+
12
+ end # describe ::ANYTHING
13
+
14
+ describe "::NOTHING" do
15
+
16
+ subject { described_class::NOTHING }
17
+ it { is_expected.to be_kind_of Nothing }
18
+
19
+ end # describe ::NOTHING
20
+
21
+ describe ".build" do
22
+
23
+ subject { described_class.build value }
24
+
25
+ context "ANYTHING" do
26
+
27
+ let(:value) { ANYTHING }
28
+ it { is_expected.to eql ANYTHING }
29
+
30
+ end # context
31
+
32
+ context "NOTHING" do
33
+
34
+ let(:value) { NOTHING }
35
+ it { is_expected.to eql NOTHING }
36
+
37
+ end # context
38
+
39
+ context "regexp" do
40
+
41
+ let(:value) { /foo/ }
42
+
43
+ it "builds the Regexp" do
44
+ expect(subject).to be_kind_of Regexp
45
+ expect(subject.attribute).to eql(/foo/)
46
+ end
47
+
48
+ end # context
49
+
50
+ context "function" do
51
+
52
+ let(:value) { -> v { v == :foo } }
53
+
54
+ it "builds the Function" do
55
+ expect(subject).to be_kind_of Function
56
+ expect(subject[:foo]).to eql(true)
57
+ expect(subject[:bar]).to eql(false)
58
+ end
59
+
60
+ end # context
61
+
62
+ context "array" do
63
+
64
+ let(:value) { [:foo, :bar] }
65
+
66
+ it "builds the Array" do
67
+ expect(subject).to be_kind_of Array
68
+ expect(subject.attribute).to eql(Set.new [:foo, :bar])
69
+ end
70
+
71
+ end # context
72
+
73
+ context "set" do
74
+
75
+ let(:value) { Set.new [:foo, :bar] }
76
+
77
+ it "builds the Array" do
78
+ expect(subject).to be_kind_of Array
79
+ expect(subject.attribute).to eql(Set.new [:foo, :bar])
80
+ end
81
+
82
+ end # context
83
+
84
+ context "range" do
85
+
86
+ let(:value) { 1..4 }
87
+
88
+ it "builds the Collection" do
89
+ expect(subject).to be_kind_of Collection
90
+ expect(subject.attribute).to eql(1..4)
91
+ end
92
+
93
+ end # context
94
+
95
+ context "single object" do
96
+
97
+ let(:value) { 1 }
98
+
99
+ it "builds the Array" do
100
+ expect(subject).to be_kind_of Array
101
+ expect(subject.attribute).to eql(Set.new [1])
102
+ end
103
+
104
+ end # context
105
+
106
+ end # describe #build
107
+
108
+ describe ".new" do
109
+
110
+ subject { described_class.new options }
111
+
112
+ context "with empty options" do
113
+
114
+ let(:options) { {} }
115
+ it { is_expected.to eql ANYTHING }
116
+
117
+ end # context
118
+
119
+ context "with a whitelist" do
120
+
121
+ let(:options) { { only: /foo/ } }
122
+
123
+ it "creates condition" do
124
+ expect(subject).to be_kind_of Regexp
125
+ expect(subject.attribute).to eql(/foo/)
126
+ end
127
+
128
+ end # context
129
+
130
+ context "with a blacklist" do
131
+
132
+ let(:options) { { except: /foo/ } }
133
+
134
+ it "creates condition" do
135
+ expect(subject).to be_kind_of Not
136
+ inverted = subject.attribute
137
+
138
+ expect(inverted).to be_kind_of Regexp
139
+ expect(inverted.attribute).to eql(/foo/)
140
+ end
141
+
142
+ end
143
+
144
+ end # describe .new
145
+
146
+ end # describe Selector
147
+
148
+ end # module Selector
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kozin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ice_nine
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hexx-rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ description:
42
+ email: andrew.kozin@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files:
46
+ - README.md
47
+ - LICENSE
48
+ files:
49
+ - ".coveralls.yml"
50
+ - ".gitignore"
51
+ - ".metrics"
52
+ - ".rspec"
53
+ - ".rubocop.yml"
54
+ - ".travis.yml"
55
+ - ".yardopts"
56
+ - CHANGELOG.md
57
+ - Gemfile
58
+ - Guardfile
59
+ - LICENSE
60
+ - README.md
61
+ - Rakefile
62
+ - config/metrics/STYLEGUIDE
63
+ - config/metrics/cane.yml
64
+ - config/metrics/churn.yml
65
+ - config/metrics/flay.yml
66
+ - config/metrics/metric_fu.yml
67
+ - config/metrics/reek.yml
68
+ - config/metrics/roodi.yml
69
+ - config/metrics/rubocop.yml
70
+ - config/metrics/saikuro.yml
71
+ - config/metrics/simplecov.yml
72
+ - config/metrics/yardstick.yml
73
+ - lib/selector.rb
74
+ - lib/selector/and.rb
75
+ - lib/selector/anything.rb
76
+ - lib/selector/array.rb
77
+ - lib/selector/collection.rb
78
+ - lib/selector/condition.rb
79
+ - lib/selector/function.rb
80
+ - lib/selector/not.rb
81
+ - lib/selector/nothing.rb
82
+ - lib/selector/or.rb
83
+ - lib/selector/regexp.rb
84
+ - lib/selector/version.rb
85
+ - selector.gemspec
86
+ - spec/integration/blacklist_spec.rb
87
+ - spec/integration/composition_spec.rb
88
+ - spec/integration/negation_spec.rb
89
+ - spec/integration/whitelist_spec.rb
90
+ - spec/shared/generator.rb
91
+ - spec/spec_helper.rb
92
+ - spec/unit/selector/and_spec.rb
93
+ - spec/unit/selector/anything_spec.rb
94
+ - spec/unit/selector/array_spec.rb
95
+ - spec/unit/selector/collection_spec.rb
96
+ - spec/unit/selector/condition_spec.rb
97
+ - spec/unit/selector/function_spec.rb
98
+ - spec/unit/selector/not_spec.rb
99
+ - spec/unit/selector/nothing_spec.rb
100
+ - spec/unit/selector/or_spec.rb
101
+ - spec/unit/selector/regexp_spec.rb
102
+ - spec/unit/selector_spec.rb
103
+ homepage: https://github.com/nepalez/selector
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 1.9.3
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.6
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Composable multi-type conditions.
127
+ test_files:
128
+ - spec/spec_helper.rb
129
+ - spec/integration/composition_spec.rb
130
+ - spec/integration/whitelist_spec.rb
131
+ - spec/integration/blacklist_spec.rb
132
+ - spec/integration/negation_spec.rb
133
+ - spec/unit/selector_spec.rb
134
+ - spec/unit/selector/anything_spec.rb
135
+ - spec/unit/selector/nothing_spec.rb
136
+ - spec/unit/selector/array_spec.rb
137
+ - spec/unit/selector/condition_spec.rb
138
+ - spec/unit/selector/function_spec.rb
139
+ - spec/unit/selector/regexp_spec.rb
140
+ - spec/unit/selector/and_spec.rb
141
+ - spec/unit/selector/not_spec.rb
142
+ - spec/unit/selector/or_spec.rb
143
+ - spec/unit/selector/collection_spec.rb
144
+ - spec/shared/generator.rb
145
+ has_rdoc: