Commit 3b06f2f
Changed files (2)
lib
scim
kit
v2
spec
scim
kit
lib/scim/kit/v2/parser.rb
@@ -1,41 +1,40 @@
# frozen_string_literal: true
+
require 'parslet'
module Scim
module Kit
module V2
-=begin
-FILTER = attrExp / logExp / valuePath / *1"not" "(" FILTER ")"
-
-valuePath = attrPath "[" valFilter "]"
- ; FILTER uses sub-attributes of a parent attrPath
-
-valFilter = attrExp / logExp / *1"not" "(" valFilter ")"
-
-attrExp = (attrPath SP "pr") /
- (attrPath SP compareOp SP compValue)
-
-logExp = FILTER SP ("and" / "or") SP FILTER
-
-compValue = false / null / true / number / string
- ; rules from JSON (RFC 7159)
-
-compareOp = "eq" / "ne" / "co" /
- "sw" / "ew" /
- "gt" / "lt" /
- "ge" / "le"
-
-attrPath = [URI ":"] ATTRNAME *1subAttr
- ; SCIM attribute name
- ; URI is SCIM "schema" URI
-
-ATTRNAME = ALPHA *(nameChar)
-
-nameChar = "-" / "_" / DIGIT / ALPHA
-
-subAttr = "." ATTRNAME
- ; a sub-attribute of a complex attribute
-=end
+ # FILTER = attrExp / logExp / valuePath / *1"not" "(" FILTER ")"
+ #
+ # valuePath = attrPath "[" valFilter "]"
+ # ; FILTER uses sub-attributes of a parent attrPath
+ #
+ # valFilter = attrExp / logExp / *1"not" "(" valFilter ")"
+ #
+ # attrExp = (attrPath SP "pr") /
+ # (attrPath SP compareOp SP compValue)
+ #
+ # logExp = FILTER SP ("and" / "or") SP FILTER
+ #
+ # compValue = false / null / true / number / string
+ # ; rules from JSON (RFC 7159)
+ #
+ # compareOp = "eq" / "ne" / "co" /
+ # "sw" / "ew" /
+ # "gt" / "lt" /
+ # "ge" / "le"
+ #
+ # attrPath = [URI ":"] ATTRNAME *1subAttr
+ # ; SCIM attribute name
+ # ; URI is SCIM "schema" URI
+ #
+ # ATTRNAME = ALPHA *(nameChar)
+ #
+ # nameChar = "-" / "_" / DIGIT / ALPHA
+ #
+ # subAttr = "." ATTRNAME
+ # ; a sub-attribute of a complex attribute
class Parser < Parslet::Parser
root :filter
rule(:filter) do
@@ -78,15 +77,15 @@ subAttr = "." ATTRNAME
rule(:null) { str('null') }
rule(:number) { digit.repeat(1) }
rule(:scim_schema_uri) { (alpha | digit | dot | colon).repeat(1) }
- rule(:equal) { str("eq") }
- rule(:not_equal) { str("ne") }
- rule(:contains) { str("co") }
- rule(:starts_with) { str("sw") }
- rule(:ends_with) { str("ew") }
- rule(:greater_than) { str("gt") }
- rule(:less_than) { str("lt") }
- rule(:greater_than_equals) { str("ge") }
- rule(:less_than_equals) { str("le") }
+ rule(:equal) { str('eq') }
+ rule(:not_equal) { str('ne') }
+ rule(:contains) { str('co') }
+ rule(:starts_with) { str('sw') }
+ rule(:ends_with) { str('ew') }
+ rule(:greater_than) { str('gt') }
+ rule(:less_than) { str('lt') }
+ rule(:greater_than_equals) { str('ge') }
+ rule(:less_than_equals) { str('le') }
rule(:string) { (alpha | single_quote | at | dot | hyphen | colon | digit).repeat(1) }
rule(:lparen) { str('(') >> space? }
rule(:rparen) { str(')') >> space? }
spec/scim/kit/v2/parser_spec.rb
@@ -8,40 +8,40 @@ RSpec.describe Scim::Kit::V2::Parser do
'name.familyName',
'urn:ietf:params:scim:schemas:core:2.0:User:userName',
'meta.lastModified',
- 'schemas',
+ 'schemas'
].each do |attribute|
- [
- "eq",
- "ne",
- "co",
- "sw",
- "ew",
- "gt",
- "lt",
- "ge",
- "le"
+ %w[
+ eq
+ ne
+ co
+ sw
+ ew
+ gt
+ lt
+ ge
+ le
].each do |operator|
[
- "bjensen",
+ 'bjensen',
"O'Malley",
- "J",
- "2011-05-13T04:42:34Z",
- "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
+ 'J',
+ '2011-05-13T04:42:34Z',
+ 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'
].each do |value|
- specify { expect(subject.parse_with_debug(%Q(#{attribute} #{operator} \"#{value}\"))).to be_truthy }
- #specify { puts subject.parse(%Q(#{attribute} #{operator} \"#{value}\")).inspect }
+ specify { expect(subject.parse_with_debug(%(#{attribute} #{operator} \"#{value}\"))).to be_truthy }
+ # specify { puts subject.parse(%Q(#{attribute} #{operator} \"#{value}\")).inspect }
end
end
end
- specify { expect(subject.parse_with_debug("userName eq \"jeramy@ziemann.biz\"")).to be_truthy }
- xspecify { expect(subject.parse_with_debug(%Q(title pr and userType eq "Employee"))).to be_truthy }
- specify { expect(subject.attribute_expression.parse_with_debug(%Q(title pr and userType eq "Employee"))).not_to be_truthy }
- specify { expect(subject.logical_expression.parse_with_debug(%Q(title pr and userType eq "Employee"))).to be_truthy }
- specify { expect(subject.value_path.parse_with_debug(%Q(title pr and userType eq "Employee"))).not_to be_truthy }
+ specify { expect(subject.parse_with_debug('userName eq "jeramy@ziemann.biz"')).to be_truthy }
+ xspecify { expect(subject.parse_with_debug(%(title pr and userType eq "Employee"))).to be_truthy }
+ specify { expect(subject.attribute_expression.parse_with_debug(%(title pr and userType eq "Employee"))).not_to be_truthy }
+ specify { expect(subject.logical_expression.parse_with_debug(%(title pr and userType eq "Employee"))).to be_truthy }
+ specify { expect(subject.value_path.parse_with_debug(%(title pr and userType eq "Employee"))).not_to be_truthy }
[
- 'emails[type eq "work" and value co "@example.com"]',
+ 'emails[type eq "work" and value co "@example.com"]'
].each do |x|
xspecify { expect(subject.value_path).to parse(x) }
end
@@ -56,23 +56,23 @@ RSpec.describe Scim::Kit::V2::Parser do
[
'firstName eq "Tsuyoshi"',
- 'firstName pr',
+ 'firstName pr'
].each do |x|
specify { expect(subject.attribute_expression).to parse(x) }
end
[
'firstName eq "Tsuyoshi" and lastName eq "Garret"',
- %Q(title pr and userType eq "Employee"),
+ %(title pr and userType eq "Employee")
].each do |x|
specify { expect(subject.logical_expression).to parse(x) }
end
- ['false', 'null', 'true', '1', 'hello', "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"].each do |x|
+ ['false', 'null', 'true', '1', 'hello', 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'].each do |x|
specify { expect(subject.comparison_value).to parse(x) }
end
- ['eq', 'ne', 'co', 'sw', 'ew', 'gt', 'lt', 'ge', 'le'].each do |x|
+ %w[eq ne co sw ew gt lt ge le].each do |x|
specify { expect(subject.comparison_operator).to parse(x) }
end
@@ -85,7 +85,7 @@ RSpec.describe Scim::Kit::V2::Parser do
'urn:ietf:params:scim:schemas:core:2.0:User:userName',
'urn:ietf:params:scim:schemas:core:2.0:User:name.familyName',
'meta.lastModified',
- 'schemas',
+ 'schemas'
].each do |x|
specify { expect(subject.attribute_path).to parse(x) }
end
@@ -95,7 +95,7 @@ RSpec.describe Scim::Kit::V2::Parser do
'user_name',
'user-name',
'username1',
- 'schemas',
+ 'schemas'
].each do |x|
specify { expect(subject.attribute_name).to parse(x) }
end
@@ -112,7 +112,7 @@ RSpec.describe Scim::Kit::V2::Parser do
[
'urn:ietf:params:scim:schemas:core:2.0:User:userName',
- 'urn:ietf:params:scim:schemas:core:2.0:User:name.familyName',
+ 'urn:ietf:params:scim:schemas:core:2.0:User:name.familyName'
].each do |x|
specify { expect(subject.scim_schema_uri).to parse(x) }
end
@@ -126,7 +126,7 @@ RSpec.describe Scim::Kit::V2::Parser do
'userType ne "Employee" and not (emails co "example.com" or emails.value co "example.org")',
'userType eq "Employee" and (emails.type eq "work") ',
'userType eq "Employee" and emails[type eq "work" and value co "@example.com"]',
- 'emails[type eq "work" and value co "@example.com"] or ims[type eq "xmpp" and value co "@foo.com"]',
+ 'emails[type eq "work" and value co "@example.com"] or ims[type eq "xmpp" and value co "@foo.com"]'
].each do |x|
xspecify { expect(subject).to parse(x) }
end
@@ -134,7 +134,7 @@ RSpec.describe Scim::Kit::V2::Parser do
[
'Tsuyoshi',
'hello@example.org',
- "2011-05-13T04:42:34Z",
+ '2011-05-13T04:42:34Z'
].each do |x|
specify { expect(subject.string).to parse(x) }
end