msfl 1.2.0 → 1.2.1.dev1
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.
- checksums.yaml +4 -4
- data/lib/msfl/datasets/base.rb +44 -0
- data/lib/msfl/datasets/car.rb +1 -1
- data/lib/msfl/datasets/person.rb +1 -1
- data/lib/msfl/sinatra.rb +1 -1
- data/lib/msfl/validators/definitions/hash_key.rb +4 -2
- data/lib/msfl/validators/semantic.rb +2 -2
- data/msfl.gemspec +2 -2
- data/spec/msfl/sinatra_spec.rb +14 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06a5c190ca1f28269f35a382637758327bb4d601
|
4
|
+
data.tar.gz: f0bfb4e6be47d3d69b6b4a568bf70247f30a9fcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f55554e68871ad1faf1421d380881229f3ef9092c4d2d37776cb1873e523291cf0915a9a0998b592820738433710f1c8f50fe7a34fa066b597a11575bbc8a6c0
|
7
|
+
data.tar.gz: b9c507c62f4dab0cd1312971b7bddc77632c94738e3b0428b36e79fd945d075274360c57bbd75087ca534f9321983ab870943a1b280fa2822173ea2481c5a3b9
|
data/lib/msfl/datasets/base.rb
CHANGED
@@ -41,6 +41,17 @@ module MSFL
|
|
41
41
|
MSFL::Datasets::Base.registered_datasets = registered_datasets
|
42
42
|
end
|
43
43
|
|
44
|
+
|
45
|
+
# Returns a new instance of the specified dataset.
|
46
|
+
#
|
47
|
+
# @param dataset_name [Symbol] the name of the dataset to instantiate
|
48
|
+
# @return [MSFL::Datasets::Base, Nil] a new instance of the specified dataset, if it can be found, otherwise nil
|
49
|
+
def self.dataset_from(dataset_name)
|
50
|
+
klass = MSFL::Datasets::Base.registered_datasets[dataset_name]
|
51
|
+
dataset = klass.new if klass
|
52
|
+
dataset ||= nil
|
53
|
+
end
|
54
|
+
|
44
55
|
# The descendant class MUST override this method otherwise all field validations will fail
|
45
56
|
#
|
46
57
|
# The method defines an array of symbols, indicating what fields are supported for the Dataset
|
@@ -50,6 +61,23 @@ module MSFL
|
|
50
61
|
raise NoMethodError, "Descendants of MSFL::Datasets::Base are required to implement the #fields method"
|
51
62
|
end
|
52
63
|
|
64
|
+
# Returns true if the specified field is valid directly or through a foreign dataset
|
65
|
+
#
|
66
|
+
# @param field_name [Symbol] the name of the field to check and see if the dataset supports it
|
67
|
+
# @return [Bool] true if the field is supported by the dataset
|
68
|
+
# @todo write direct test of this
|
69
|
+
def has_field?(field_name)
|
70
|
+
direct_fields = self.fields
|
71
|
+
foreigns.each do |f|
|
72
|
+
foreign_dataset = self.class.dataset_from f
|
73
|
+
if foreign_dataset
|
74
|
+
direct_fields.concat foreign_dataset.fields
|
75
|
+
end
|
76
|
+
end
|
77
|
+
direct_fields.include? field_name
|
78
|
+
end
|
79
|
+
|
80
|
+
|
53
81
|
# The descendant class SHOULD override this method, in future versions of MSFL it is execpted to
|
54
82
|
# become a MUST for descendants to override.
|
55
83
|
#
|
@@ -73,6 +101,22 @@ module MSFL
|
|
73
101
|
hash_key_operators
|
74
102
|
end
|
75
103
|
|
104
|
+
# If the dataset supports the operator this method returns true
|
105
|
+
#
|
106
|
+
# @param operator [Symbol] the operator to check if the dataset supports it
|
107
|
+
# @return [Bool] true if the dataset supports the operator
|
108
|
+
# @todo write test of this guy
|
109
|
+
def has_operator?(operator)
|
110
|
+
ops = operators
|
111
|
+
foreigns.each do |f|
|
112
|
+
foreign_dataset = self.class.dataset_from f
|
113
|
+
if foreign_dataset
|
114
|
+
ops.concat foreign_dataset.operators
|
115
|
+
end
|
116
|
+
end
|
117
|
+
ops.include? operator
|
118
|
+
end
|
119
|
+
|
76
120
|
# This method returns the errors argument. The errors argument is unchanged if type conformity validation passes,
|
77
121
|
# otherwise an error is added to errors.
|
78
122
|
#
|
data/lib/msfl/datasets/car.rb
CHANGED
data/lib/msfl/datasets/person.rb
CHANGED
data/lib/msfl/sinatra.rb
CHANGED
@@ -27,7 +27,7 @@ module MSFL
|
|
27
27
|
def dataset_from(params)
|
28
28
|
dataset_name = params[:dataset].to_sym unless params[:dataset].nil?
|
29
29
|
dataset_name ||= nil
|
30
|
-
Datasets::Base.
|
30
|
+
Datasets::Base.dataset_from dataset_name
|
31
31
|
end
|
32
32
|
|
33
33
|
# Creates a semantic validator instance that is ready to validate the dataset
|
@@ -4,7 +4,7 @@ module MSFL
|
|
4
4
|
module HashKey
|
5
5
|
|
6
6
|
def valid_hash_key?(key)
|
7
|
-
|
7
|
+
self.dataset.has_operator?(key) || self.dataset.has_field?(key)
|
8
8
|
end
|
9
9
|
|
10
10
|
def valid_hash_keys
|
@@ -30,7 +30,9 @@ module MSFL
|
|
30
30
|
:gt, # >
|
31
31
|
:gte, # >=
|
32
32
|
:neg, # logical negation
|
33
|
-
|
33
|
+
:foreign, # Defines a filter on a related item
|
34
|
+
:dataset, # A foreign dataset
|
35
|
+
:filter, # an explicit filter
|
34
36
|
]
|
35
37
|
end
|
36
38
|
|
@@ -73,10 +73,10 @@ module MSFL
|
|
73
73
|
# Then make a recursive call to validate on the value so that it and its elements are validated
|
74
74
|
# later I might be able to optimize this by only making the recursive call for Sets and Hashes
|
75
75
|
#
|
76
|
-
if dataset.
|
76
|
+
if dataset.has_operator? key
|
77
77
|
dataset.validate_operator_conforms key, current_field, errors
|
78
78
|
opts[:parent_operator] = key
|
79
|
-
elsif dataset.
|
79
|
+
elsif dataset.has_field? key
|
80
80
|
current_field = key
|
81
81
|
dataset.validate_type_conforms value, current_field, errors
|
82
82
|
dataset.validate_value_conforms value, current_field, errors
|
data/msfl.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'msfl'
|
3
|
-
s.version = '1.2.
|
4
|
-
s.date = '2015-05-
|
3
|
+
s.version = '1.2.1.dev1'
|
4
|
+
s.date = '2015-05-20'
|
5
5
|
s.summary = "MSFL in Ruby"
|
6
6
|
s.description = "Serializers, validators, and other tasty goodness for the Mattermark Semantic Filter Language in Ruby."
|
7
7
|
s.authors = ["Courtland Caldwell"]
|
data/spec/msfl/sinatra_spec.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'msfl/datasets/car'
|
3
|
+
require 'msfl/datasets/person'
|
2
4
|
|
3
5
|
|
4
6
|
describe "MSFL::Sinatra" do
|
@@ -93,5 +95,17 @@ describe "MSFL::Sinatra" do
|
|
93
95
|
let(:params) { nil }
|
94
96
|
|
95
97
|
it_behaves_like "an invocation of MSFL::Sinatra.validate"
|
98
|
+
|
99
|
+
context "when validating a foreign" do
|
100
|
+
|
101
|
+
context "when the foreign is valid" do
|
102
|
+
|
103
|
+
let(:params) { { dataset: :car, filter: filter } }
|
104
|
+
|
105
|
+
let(:filter) { { foreign: { dataset: 'person', filter: { age: { gte: 25 } } } } }
|
106
|
+
|
107
|
+
it { is_expected.to eq true }
|
108
|
+
end
|
109
|
+
end
|
96
110
|
end
|
97
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msfl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1.dev1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Courtland Caldwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -152,9 +152,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
|
-
- - "
|
155
|
+
- - ">"
|
156
156
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
157
|
+
version: 1.3.1
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project:
|
160
160
|
rubygems_version: 2.2.2
|