object_selector 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e25c39ccad43e1297ea8e6f4e3b26dd33968e22
4
- data.tar.gz: 1f5d3812b7c2ec7e03e749867df4f259b9d5cfd0
3
+ metadata.gz: 66e717c3577951bc8852113b1608059aa2a97a3d
4
+ data.tar.gz: f38b7984116c716d0dd23873e35feb4060fea914
5
5
  SHA512:
6
- metadata.gz: 466d7b7427b34803eb3c317ff5efb38f6462d82daeb284f9bdfb5391bbc4bc38e2b37fdd62c47c696bda10d34a4be494b9831c12e3788080d65cd6ea61fd9112
7
- data.tar.gz: 57cd52815a0cf9ed6c876bc822e8bb6be5779e0dcfccb16e8237023795381c4fa87332f2eafe59cf25dfa1263e9eec5f4faacec5cf52aeec48d011073a18fc59
6
+ metadata.gz: 8e080caef68f3343f750c59781ac1d4491ec6549a75c1494543303ef025cbe7e696efd4667cb7c06a457a56689b733b2669599798ce24aa3a3a89e8badcace27
7
+ data.tar.gz: eb15a6030a0279f87f7db9dbf91073dee0fe53e92e15e48a5c3cff2de59413086f1df415e6bf4409bc9f578ebb0e713e0607010825ab564001f97194aa40bee7
data/.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "object_selector"
3
- spec.version = "0.0.2"
3
+ spec.version = "1.0.0"
4
4
  spec.authors = ["Charles Mulder"]
5
5
  spec.email = ["charles.mulder@hetzner.co.za"]
6
6
 
data/Dockerfile ADDED
@@ -0,0 +1,6 @@
1
+ FROM ruby:2.3
2
+ WORKDIR /usr/local/src
3
+ ADD Gemfile .gemspec /usr/local/src/
4
+ RUN bundle install --without development --with test
5
+ ADD . /usr/local/src/
6
+ CMD bundle exec rspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- object_selector-regex_rule_list (0.0.1)
4
+ object_selector (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -25,8 +25,8 @@ PLATFORMS
25
25
  ruby
26
26
 
27
27
  DEPENDENCIES
28
- object_selector-regex_rule_list!
28
+ object_selector!
29
29
  rspec (~> 3.5)
30
30
 
31
31
  BUNDLED WITH
32
- 1.14.3
32
+ 1.14.4
data/README.md CHANGED
@@ -1,25 +1,43 @@
1
1
  # Object Selector
2
2
 
3
- ## Regex Rule List
3
+ ## Regex Rule List Provider
4
4
 
5
5
  ### Quickstart
6
6
  ```ruby
7
- > Struct.new('MyObject')
8
- > selected_object = ObjectSelector::RegexRuleList.select({
9
- value: SecureRandom.hex,
10
- rules: [{
11
- regex: /\w/,
12
- object: Struct::MyObject.new
13
- }]
14
- })
15
- > puts selected_object.class.name
16
- Struct::MyObject
7
+ > Struct.new("MyFirstObject")
8
+ > Struct.new("MySecondObject")
9
+ > selector = ObjectSelector.new(
10
+ ObjectSelector::Provider::RegexRuleList.new({
11
+ rules: [
12
+ {
13
+ regex: /\D/,
14
+ object: Struct::MyFirstObject.new
15
+ }, {
16
+ regex: /\d/,
17
+ object: Struct::MySecondObject.new
18
+ }
19
+ ]
20
+ })
21
+ )
22
+
23
+ > selector.select("not a digit")
24
+ Struct::MyFirstObject
25
+
26
+ > selector.select(123)
27
+ Struct::MySecondObject
17
28
  ```
18
29
 
19
30
  ### Testing
20
31
 
21
32
  #### Local
33
+ ```bash
34
+ $ bundle exec rspec
35
+ ```
22
36
 
37
+ #### CI
23
38
  ```bash
24
- $ rspec
39
+ docker-compose --file docker-compose.yml --project-name object_selector-provider-regex_rule_list up --abort-on-container-exit --remove-orphans --build --force-recreate
40
+ EXIT_CODE=$(docker ps -a -f "name=objectselectorproviderregexrulelist_tests" -q | xargs docker inspect -f "{{ .State.ExitCode }}")
41
+ docker-compose --file docker-compose.yml --project-name object_selector-provider-regex_rule_list down --rmi local
42
+ exit $EXIT_CODE
25
43
  ```
@@ -0,0 +1,4 @@
1
+ version: "2"
2
+ services:
3
+ tests:
4
+ build: .
@@ -0,0 +1,9 @@
1
+ require 'object_selector/model'
2
+
3
+ module ObjectSelector
4
+
5
+ def self.new(provider)
6
+ ObjectSelector::Model.new(provider)
7
+ end
8
+
9
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module ObjectSelector
3
+ module Error
4
+ class NoMatchError < StandardError; end;
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ require 'object_selector/provider/regex_rule_list'
2
+ require 'object_selector/error'
3
+
4
+ module ObjectSelector
5
+
6
+ class Model
7
+ ##
8
+ # @param [ObjectSelector::Provider::RegexRuleList] provider
9
+ ##
10
+ def initialize(provider)
11
+ @provider = provider
12
+ end
13
+
14
+ ##
15
+ # @param [String] value to match
16
+ # @return [Object]
17
+ ##
18
+ def select(value)
19
+ @provider.select(value)
20
+ end
21
+ end
22
+
23
+
24
+ end
@@ -0,0 +1,33 @@
1
+
2
+ module ObjectSelector
3
+ module Provider
4
+
5
+ class RegexRuleList
6
+
7
+ ##
8
+ # @param [Array<Hash>] rules
9
+ # @option rules [Regex] :regex
10
+ # @option rules [Object] :object
11
+ ##
12
+ def initialize(rules:)
13
+ raise ArgumentError, 'Rules should be an array' if not rules.is_a?(Array)
14
+ @rules = rules
15
+ end
16
+
17
+ ##
18
+ # @param [String] value to match against the regex key in rules
19
+ # @return [Object] returns selected object key in rules
20
+ # @raise [ObjectSelector::Error::NoMatchError]
21
+ ##
22
+ def select(value)
23
+ object = @rules.each { |rule|
24
+ break rule[:object] if rule[:regex].match(value)
25
+ }
26
+ raise ObjectSelector::RegexRuleList::NoMatchError, 'No rules matched' if object.is_a?(Array) and object.empty?
27
+ return object
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object_selector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Mulder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-07 00:00:00.000000000 Z
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -22,10 +22,15 @@ files:
22
22
  - ".rspec"
23
23
  - ".ruby-gemset"
24
24
  - ".ruby-version"
25
+ - Dockerfile
25
26
  - Gemfile
26
27
  - Gemfile.lock
27
28
  - README.md
28
- - lib/object_selector/regex_rule_list.rb
29
+ - docker-compose.yml
30
+ - lib/object_selector.rb
31
+ - lib/object_selector/error.rb
32
+ - lib/object_selector/model.rb
33
+ - lib/object_selector/provider/regex_rule_list.rb
29
34
  homepage: https://github.com/hetznerZA/object_selector-regex_rule_list
30
35
  licenses: []
31
36
  metadata: {}
@@ -1,22 +0,0 @@
1
- module ObjectSelector
2
- class RegexRuleList
3
-
4
- class NoMatchError < StandardError; end;
5
-
6
- ##
7
- # @param rules [Array] List of hashes keyed by regex and object
8
- # @param value [String] Value use to match against the regex key in rules
9
- # @return [Object] Returns selected object key in rules
10
- # @raise [ObjectSelector::RegexRuleList::NoMatchError]
11
- ##
12
- def self.select(rules: [], value: "")
13
- object = rules.each { |rule|
14
- break rule[:object] if rule[:regex].match(value)
15
- }
16
- raise ObjectSelector::RegexRuleList::NoMatchError, 'No rules matched' if object.is_a?(Array) and object.empty?
17
- return object
18
- end
19
-
20
- end
21
-
22
- end