chef-zero 4.2.3 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +201 -201
- data/README.md +155 -150
- data/Rakefile +31 -31
- data/bin/chef-zero +100 -100
- data/lib/chef_zero.rb +10 -7
- data/lib/chef_zero/chef_data/acl_path.rb +139 -139
- data/lib/chef_zero/chef_data/cookbook_data.rb +240 -240
- data/lib/chef_zero/chef_data/data_normalizer.rb +207 -207
- data/lib/chef_zero/chef_data/default_creator.rb +446 -446
- data/lib/chef_zero/data_store/data_already_exists_error.rb +29 -29
- data/lib/chef_zero/data_store/data_error.rb +31 -31
- data/lib/chef_zero/data_store/data_not_found_error.rb +28 -28
- data/lib/chef_zero/data_store/default_facade.rb +149 -149
- data/lib/chef_zero/data_store/interface_v1.rb +67 -67
- data/lib/chef_zero/data_store/interface_v2.rb +18 -18
- data/lib/chef_zero/data_store/memory_store.rb +33 -33
- data/lib/chef_zero/data_store/memory_store_v2.rb +155 -155
- data/lib/chef_zero/data_store/raw_file_store.rb +147 -147
- data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +142 -142
- data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +107 -107
- data/lib/chef_zero/endpoints/acl_endpoint.rb +38 -38
- data/lib/chef_zero/endpoints/acls_endpoint.rb +29 -29
- data/lib/chef_zero/endpoints/actor_endpoint.rb +94 -88
- data/lib/chef_zero/endpoints/actors_endpoint.rb +64 -64
- data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +31 -31
- data/lib/chef_zero/endpoints/container_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/containers_endpoint.rb +13 -13
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +39 -39
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +119 -119
- data/lib/chef_zero/endpoints/cookbooks_base.rb +65 -65
- data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/data_bag_endpoint.rb +45 -45
- data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/data_bags_endpoint.rb +23 -23
- data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +123 -123
- data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/environment_endpoint.rb +33 -33
- data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +23 -23
- data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/environment_role_endpoint.rb +36 -36
- data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/group_endpoint.rb +20 -20
- data/lib/chef_zero/endpoints/groups_endpoint.rb +13 -13
- data/lib/chef_zero/endpoints/license_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/node_endpoint.rb +17 -17
- data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +22 -0
- data/lib/chef_zero/endpoints/not_found_endpoint.rb +11 -11
- data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +30 -29
- data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/organization_endpoint.rb +46 -41
- data/lib/chef_zero/endpoints/organization_user_base.rb +15 -0
- data/lib/chef_zero/endpoints/organization_user_endpoint.rb +26 -48
- data/lib/chef_zero/endpoints/organization_users_endpoint.rb +43 -14
- data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +20 -20
- data/lib/chef_zero/endpoints/organizations_endpoint.rb +62 -55
- data/lib/chef_zero/endpoints/policies_endpoint.rb +151 -154
- data/lib/chef_zero/endpoints/principal_endpoint.rb +42 -42
- data/lib/chef_zero/endpoints/rest_list_endpoint.rb +42 -42
- data/lib/chef_zero/endpoints/rest_object_endpoint.rb +63 -63
- data/lib/chef_zero/endpoints/role_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/role_environments_endpoint.rb +14 -14
- data/lib/chef_zero/endpoints/sandbox_endpoint.rb +27 -27
- data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +50 -50
- data/lib/chef_zero/endpoints/search_endpoint.rb +194 -192
- data/lib/chef_zero/endpoints/searches_endpoint.rb +18 -18
- data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +14 -0
- data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +30 -30
- data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +40 -40
- data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/version_endpoint.rb +12 -12
- data/lib/chef_zero/log.rb +7 -7
- data/lib/chef_zero/rest_base.rb +242 -214
- data/lib/chef_zero/rest_error_response.rb +11 -11
- data/lib/chef_zero/rest_request.rb +69 -65
- data/lib/chef_zero/rest_router.rb +45 -45
- data/lib/chef_zero/rspec.rb +308 -308
- data/lib/chef_zero/server.rb +642 -637
- data/lib/chef_zero/socketless_server_map.rb +92 -92
- data/lib/chef_zero/solr/query/binary_operator.rb +52 -52
- data/lib/chef_zero/solr/query/phrase.rb +23 -23
- data/lib/chef_zero/solr/query/range_query.rb +46 -46
- data/lib/chef_zero/solr/query/regexpable_query.rb +29 -29
- data/lib/chef_zero/solr/query/subquery.rb +37 -37
- data/lib/chef_zero/solr/query/term.rb +45 -45
- data/lib/chef_zero/solr/query/unary_operator.rb +43 -43
- data/lib/chef_zero/solr/solr_doc.rb +53 -53
- data/lib/chef_zero/solr/solr_parser.rb +203 -203
- data/lib/chef_zero/version.rb +3 -3
- data/spec/run_oc_pedant.rb +63 -56
- data/spec/search_spec.rb +32 -32
- data/spec/server_spec.rb +92 -91
- data/spec/socketless_server_map_spec.rb +76 -76
- data/spec/support/oc_pedant.rb +132 -134
- data/spec/support/stickywicket.pem +27 -27
- metadata +10 -15
- data/spec/run_pedant.rb +0 -103
- data/spec/support/pedant.rb +0 -129
@@ -1,92 +1,92 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Daniel DeLeo (<dan@chef.io>)
|
3
|
-
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'thread'
|
20
|
-
require 'singleton'
|
21
|
-
|
22
|
-
module ChefZero
|
23
|
-
|
24
|
-
class ServerNotFound < StandardError
|
25
|
-
end
|
26
|
-
|
27
|
-
class NoSocketlessPortAvailable < StandardError
|
28
|
-
end
|
29
|
-
|
30
|
-
class SocketlessServerMap
|
31
|
-
|
32
|
-
def self.request(port, request_env)
|
33
|
-
instance.request(port, request_env)
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.server_on_port(port)
|
37
|
-
instance.server_on_port(port)
|
38
|
-
end
|
39
|
-
|
40
|
-
MUTEX = Mutex.new
|
41
|
-
|
42
|
-
include Singleton
|
43
|
-
|
44
|
-
def initialize()
|
45
|
-
reset!
|
46
|
-
end
|
47
|
-
|
48
|
-
def reset!
|
49
|
-
@servers_by_port = {}
|
50
|
-
end
|
51
|
-
|
52
|
-
def register_port(port, server)
|
53
|
-
MUTEX.synchronize do
|
54
|
-
@servers_by_port[port] = server
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def register_no_listen_server(server)
|
59
|
-
MUTEX.synchronize do
|
60
|
-
1.upto(1000) do |port|
|
61
|
-
unless @servers_by_port.key?(port)
|
62
|
-
@servers_by_port[port] = server
|
63
|
-
return port
|
64
|
-
end
|
65
|
-
end
|
66
|
-
raise NoSocketlessPortAvailable, "No socketless ports left to register"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def has_server_on_port?(port)
|
71
|
-
@servers_by_port.key?(port)
|
72
|
-
end
|
73
|
-
|
74
|
-
def server_on_port(port)
|
75
|
-
@servers_by_port[port]
|
76
|
-
end
|
77
|
-
|
78
|
-
def deregister(port)
|
79
|
-
MUTEX.synchronize do
|
80
|
-
@servers_by_port.delete(port)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def request(port, request_env)
|
85
|
-
server = @servers_by_port[port]
|
86
|
-
raise ServerNotFound, "No socketless chef-zero server on given port #{port.inspect}" unless server
|
87
|
-
server.handle_socketless_request(request_env)
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
1
|
+
#
|
2
|
+
# Author:: Daniel DeLeo (<dan@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'thread'
|
20
|
+
require 'singleton'
|
21
|
+
|
22
|
+
module ChefZero
|
23
|
+
|
24
|
+
class ServerNotFound < StandardError
|
25
|
+
end
|
26
|
+
|
27
|
+
class NoSocketlessPortAvailable < StandardError
|
28
|
+
end
|
29
|
+
|
30
|
+
class SocketlessServerMap
|
31
|
+
|
32
|
+
def self.request(port, request_env)
|
33
|
+
instance.request(port, request_env)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.server_on_port(port)
|
37
|
+
instance.server_on_port(port)
|
38
|
+
end
|
39
|
+
|
40
|
+
MUTEX = Mutex.new
|
41
|
+
|
42
|
+
include Singleton
|
43
|
+
|
44
|
+
def initialize()
|
45
|
+
reset!
|
46
|
+
end
|
47
|
+
|
48
|
+
def reset!
|
49
|
+
@servers_by_port = {}
|
50
|
+
end
|
51
|
+
|
52
|
+
def register_port(port, server)
|
53
|
+
MUTEX.synchronize do
|
54
|
+
@servers_by_port[port] = server
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def register_no_listen_server(server)
|
59
|
+
MUTEX.synchronize do
|
60
|
+
1.upto(1000) do |port|
|
61
|
+
unless @servers_by_port.key?(port)
|
62
|
+
@servers_by_port[port] = server
|
63
|
+
return port
|
64
|
+
end
|
65
|
+
end
|
66
|
+
raise NoSocketlessPortAvailable, "No socketless ports left to register"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def has_server_on_port?(port)
|
71
|
+
@servers_by_port.key?(port)
|
72
|
+
end
|
73
|
+
|
74
|
+
def server_on_port(port)
|
75
|
+
@servers_by_port[port]
|
76
|
+
end
|
77
|
+
|
78
|
+
def deregister(port)
|
79
|
+
MUTEX.synchronize do
|
80
|
+
@servers_by_port.delete(port)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def request(port, request_env)
|
85
|
+
server = @servers_by_port[port]
|
86
|
+
raise ServerNotFound, "No socketless chef-zero server on given port #{port.inspect}" unless server
|
87
|
+
server.handle_socketless_request(request_env)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
@@ -1,52 +1,52 @@
|
|
1
|
-
module ChefZero
|
2
|
-
module Solr
|
3
|
-
module Query
|
4
|
-
class BinaryOperator
|
5
|
-
def initialize(left, operator, right)
|
6
|
-
@left = left
|
7
|
-
@operator = operator
|
8
|
-
@right = right
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
"(#{left} #{operator} #{right})"
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_reader :left
|
16
|
-
attr_reader :operator
|
17
|
-
attr_reader :right
|
18
|
-
|
19
|
-
def matches_doc?(doc)
|
20
|
-
case @operator
|
21
|
-
when 'AND'
|
22
|
-
left.matches_doc?(doc) && right.matches_doc?(doc)
|
23
|
-
when 'OR'
|
24
|
-
left.matches_doc?(doc) || right.matches_doc?(doc)
|
25
|
-
when '^'
|
26
|
-
left.matches_doc?(doc)
|
27
|
-
when ':'
|
28
|
-
if left.respond_to?(:literal_string) && left.literal_string
|
29
|
-
values = doc[left.literal_string]
|
30
|
-
else
|
31
|
-
values = doc.matching_values { |key| left.matches_values?([key]) }
|
32
|
-
end
|
33
|
-
right.matches_values?(values)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def matches_values?(values)
|
38
|
-
case @operator
|
39
|
-
when 'AND'
|
40
|
-
left.matches_values?(values) && right.matches_values?(values)
|
41
|
-
when 'OR'
|
42
|
-
left.matches_values?(values) || right.matches_values?(values)
|
43
|
-
when '^'
|
44
|
-
left.matches_values?(values)
|
45
|
-
when ':'
|
46
|
-
raise ": does not work inside a : or term"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
1
|
+
module ChefZero
|
2
|
+
module Solr
|
3
|
+
module Query
|
4
|
+
class BinaryOperator
|
5
|
+
def initialize(left, operator, right)
|
6
|
+
@left = left
|
7
|
+
@operator = operator
|
8
|
+
@right = right
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"(#{left} #{operator} #{right})"
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :left
|
16
|
+
attr_reader :operator
|
17
|
+
attr_reader :right
|
18
|
+
|
19
|
+
def matches_doc?(doc)
|
20
|
+
case @operator
|
21
|
+
when 'AND'
|
22
|
+
left.matches_doc?(doc) && right.matches_doc?(doc)
|
23
|
+
when 'OR'
|
24
|
+
left.matches_doc?(doc) || right.matches_doc?(doc)
|
25
|
+
when '^'
|
26
|
+
left.matches_doc?(doc)
|
27
|
+
when ':'
|
28
|
+
if left.respond_to?(:literal_string) && left.literal_string
|
29
|
+
values = doc[left.literal_string]
|
30
|
+
else
|
31
|
+
values = doc.matching_values { |key| left.matches_values?([key]) }
|
32
|
+
end
|
33
|
+
right.matches_values?(values)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def matches_values?(values)
|
38
|
+
case @operator
|
39
|
+
when 'AND'
|
40
|
+
left.matches_values?(values) && right.matches_values?(values)
|
41
|
+
when 'OR'
|
42
|
+
left.matches_values?(values) || right.matches_values?(values)
|
43
|
+
when '^'
|
44
|
+
left.matches_values?(values)
|
45
|
+
when ':'
|
46
|
+
raise ": does not work inside a : or term"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
require 'chef_zero/solr/query/regexpable_query'
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Solr
|
5
|
-
module Query
|
6
|
-
class Phrase < RegexpableQuery
|
7
|
-
def initialize(terms)
|
8
|
-
# Phrase is terms separated by whitespace
|
9
|
-
if terms.size == 0 && terms[0].literal_string
|
10
|
-
literal_string = terms[0].literal_string
|
11
|
-
else
|
12
|
-
literal_string = nil
|
13
|
-
end
|
14
|
-
super(terms.map { |term| term.regexp_string }.join("#{NON_WORD_CHARACTER}+"), literal_string)
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_s
|
18
|
-
"Phrase(\"#{@regexp_string}\")"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
1
|
+
require 'chef_zero/solr/query/regexpable_query'
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Solr
|
5
|
+
module Query
|
6
|
+
class Phrase < RegexpableQuery
|
7
|
+
def initialize(terms)
|
8
|
+
# Phrase is terms separated by whitespace
|
9
|
+
if terms.size == 0 && terms[0].literal_string
|
10
|
+
literal_string = terms[0].literal_string
|
11
|
+
else
|
12
|
+
literal_string = nil
|
13
|
+
end
|
14
|
+
super(terms.map { |term| term.regexp_string }.join("#{NON_WORD_CHARACTER}+"), literal_string)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"Phrase(\"#{@regexp_string}\")"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,46 +1,46 @@
|
|
1
|
-
module ChefZero
|
2
|
-
module Solr
|
3
|
-
module Query
|
4
|
-
class RangeQuery
|
5
|
-
def initialize(from, to, from_inclusive, to_inclusive)
|
6
|
-
@from = from
|
7
|
-
@to = to
|
8
|
-
@from_inclusive = from_inclusive
|
9
|
-
@to_inclusive = to_inclusive
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
"#{@from_inclusive ? '[' : '{'}#{@from} TO #{@to}#{@to_inclusive ? ']' : '}'}"
|
14
|
-
end
|
15
|
-
|
16
|
-
def matches_values?(values)
|
17
|
-
values.any? do |value|
|
18
|
-
unless @from == '*'
|
19
|
-
case @from <=> value
|
20
|
-
when -1
|
21
|
-
return false
|
22
|
-
when 0
|
23
|
-
return false if !@from_inclusive
|
24
|
-
end
|
25
|
-
end
|
26
|
-
unless @to == '*'
|
27
|
-
case value <=> @to
|
28
|
-
when 1
|
29
|
-
return false
|
30
|
-
when 0
|
31
|
-
return false if !@to_inclusive
|
32
|
-
end
|
33
|
-
end
|
34
|
-
return true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def matches_doc?(doc)
|
39
|
-
matches_values?(doc[DEFAULT_FIELD])
|
40
|
-
end
|
41
|
-
|
42
|
-
DEFAULT_FIELD = "text"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
1
|
+
module ChefZero
|
2
|
+
module Solr
|
3
|
+
module Query
|
4
|
+
class RangeQuery
|
5
|
+
def initialize(from, to, from_inclusive, to_inclusive)
|
6
|
+
@from = from
|
7
|
+
@to = to
|
8
|
+
@from_inclusive = from_inclusive
|
9
|
+
@to_inclusive = to_inclusive
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"#{@from_inclusive ? '[' : '{'}#{@from} TO #{@to}#{@to_inclusive ? ']' : '}'}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def matches_values?(values)
|
17
|
+
values.any? do |value|
|
18
|
+
unless @from == '*'
|
19
|
+
case @from <=> value
|
20
|
+
when -1
|
21
|
+
return false
|
22
|
+
when 0
|
23
|
+
return false if !@from_inclusive
|
24
|
+
end
|
25
|
+
end
|
26
|
+
unless @to == '*'
|
27
|
+
case value <=> @to
|
28
|
+
when 1
|
29
|
+
return false
|
30
|
+
when 0
|
31
|
+
return false if !@to_inclusive
|
32
|
+
end
|
33
|
+
end
|
34
|
+
return true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def matches_doc?(doc)
|
39
|
+
matches_values?(doc[DEFAULT_FIELD])
|
40
|
+
end
|
41
|
+
|
42
|
+
DEFAULT_FIELD = "text"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
module ChefZero
|
2
|
-
module Solr
|
3
|
-
module Query
|
4
|
-
class RegexpableQuery
|
5
|
-
def initialize(regexp_string, literal_string)
|
6
|
-
@regexp_string = regexp_string
|
7
|
-
# Surround the regexp with word boundaries
|
8
|
-
@regexp = Regexp.new("(^|#{NON_WORD_CHARACTER})#{regexp_string}($|#{NON_WORD_CHARACTER})", true)
|
9
|
-
@literal_string = literal_string
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_reader :literal_string
|
13
|
-
attr_reader :regexp_string
|
14
|
-
attr_reader :regexp
|
15
|
-
|
16
|
-
def matches_doc?(doc)
|
17
|
-
matches_values?(doc[DEFAULT_FIELD])
|
18
|
-
end
|
19
|
-
def matches_values?(values)
|
20
|
-
values.any? { |value| !@regexp.match(value).nil? }
|
21
|
-
end
|
22
|
-
|
23
|
-
DEFAULT_FIELD = "text"
|
24
|
-
WORD_CHARACTER = "[A-Za-z0-9@._':]"
|
25
|
-
NON_WORD_CHARACTER = "[^A-Za-z0-9@._':]"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
1
|
+
module ChefZero
|
2
|
+
module Solr
|
3
|
+
module Query
|
4
|
+
class RegexpableQuery
|
5
|
+
def initialize(regexp_string, literal_string)
|
6
|
+
@regexp_string = regexp_string
|
7
|
+
# Surround the regexp with word boundaries
|
8
|
+
@regexp = Regexp.new("(^|#{NON_WORD_CHARACTER})#{regexp_string}($|#{NON_WORD_CHARACTER})", true)
|
9
|
+
@literal_string = literal_string
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :literal_string
|
13
|
+
attr_reader :regexp_string
|
14
|
+
attr_reader :regexp
|
15
|
+
|
16
|
+
def matches_doc?(doc)
|
17
|
+
matches_values?(doc[DEFAULT_FIELD])
|
18
|
+
end
|
19
|
+
def matches_values?(values)
|
20
|
+
values.any? { |value| !@regexp.match(value).nil? }
|
21
|
+
end
|
22
|
+
|
23
|
+
DEFAULT_FIELD = "text"
|
24
|
+
WORD_CHARACTER = "[A-Za-z0-9@._':]"
|
25
|
+
NON_WORD_CHARACTER = "[^A-Za-z0-9@._':]"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|