smart_params 5.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -30
- data/lib/smart_params/field.rb +35 -134
- data/lib/smart_params/fluent_language.rb +46 -0
- data/lib/smart_params/invalid_payload_exception.rb +16 -0
- data/lib/smart_params/invalid_property_type_exception.rb +33 -0
- data/lib/smart_params/missing_property_exception.rb +18 -0
- data/lib/smart_params/namespace_already_defined_exception.rb +14 -0
- data/lib/smart_params/no_matching_namespace_exception.rb +15 -0
- data/lib/smart_params/version.rb +1 -1
- data/lib/smart_params.rb +36 -89
- data/lib/smart_params_spec.rb +145 -290
- metadata +16 -27
- data/lib/smart_params/error/invalid_property_type.rb +0 -36
- data/lib/smart_params/error/invalid_property_type_spec.rb +0 -25
- data/lib/smart_params/error.rb +0 -7
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SmartParams
|
4
|
-
class Error
|
5
|
-
class InvalidPropertyType < Error
|
6
|
-
attr_reader :keychain
|
7
|
-
attr_reader :wanted
|
8
|
-
attr_reader :raw
|
9
|
-
attr_reader :missing_key
|
10
|
-
|
11
|
-
def initialize(keychain:, wanted:, raw:, missing_key: nil)
|
12
|
-
super
|
13
|
-
@keychain = keychain
|
14
|
-
@wanted = wanted
|
15
|
-
@raw = raw
|
16
|
-
@missing_key = missing_key
|
17
|
-
end
|
18
|
-
|
19
|
-
def message
|
20
|
-
if missing_key
|
21
|
-
"expected #{keychain.inspect} to be #{wanted.name} with key #{missing_key.inspect}, but is #{raw.inspect}"
|
22
|
-
else
|
23
|
-
"expected #{keychain.inspect} to be #{wanted.name}, but is #{raw.inspect}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def as_json
|
28
|
-
{
|
29
|
-
"keychain" => keychain,
|
30
|
-
"wanted" => wanted.name,
|
31
|
-
"raw" => raw
|
32
|
-
}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
RSpec.describe SmartParams::Error::InvalidPropertyType do
|
6
|
-
describe "#message" do
|
7
|
-
subject { error.message }
|
8
|
-
|
9
|
-
context "when the error is about the type mismatch" do
|
10
|
-
let(:error) { described_class.new(keychain: [:data], wanted: SmartParams::Strict::Hash, raw: "") }
|
11
|
-
|
12
|
-
it "returns the message" do
|
13
|
-
expect(subject).to eq("expected [:data] to be Hash, but is \"\"")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when the error is about a missing key" do
|
18
|
-
let(:error) { described_class.new(keychain: [:data], wanted: SmartParams::Strict::Hash.schema(data: SmartParams::Strict::String), raw: {}, missing_key: :data) }
|
19
|
-
|
20
|
-
it "returns the message" do
|
21
|
-
expect(subject).to eq("expected [:data] to be Hash with key :data, but is {}")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|