simple_params 0.0.2.pre6 → 0.0.2.pre7
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 +8 -8
- data/Gemfile.lock +1 -1
- data/lib/simple_params/api_pie_doc/attribute.rb +1 -1
- data/lib/simple_params/attribute.rb +4 -2
- data/lib/simple_params/params.rb +2 -1
- data/lib/simple_params/version.rb +1 -1
- data/spec/acceptance_spec.rb +11 -1
- data/spec/attribute_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGJkNjAzNzZhMWU3YmZjOGVhMGVlNjAxM2QyZjkwZDM2NjdiMDAxZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTVlYWJiMmI1NjlmNWNlZjc4ZDdkZjIwNDY5NjFjNmNhODgxZDExZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmRiYTg4NDRiOGY0NmFjMjg1YmQ2ZTI1M2UzOTA4NDUxNmUwZjdiODNhY2Q1
|
10
|
+
OTE4Mjk4OGY4ZmVlZTQ5ZTRmZTdiOTEzN2I0YjBlMDljMzIwMGVkZGM0Nzlm
|
11
|
+
MmMxYzBkN2NmNzMwMzc3ZGE0MjdmZDFmM2JjMTFhNzUwNjNhMzc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmMxZGY0NjgwNDIwOWZiMTY0NGFmYTNmOWYxZTU1NjhiMGU4N2RkNWJmYWY1
|
14
|
+
YTY4YjFlMzM4ZjAyMDcxYmIyODk5MzJmMzVjMzAyNmE4OWJkOTU4Mjk3Y2Iz
|
15
|
+
MWZiMDUzYzIzMGQxMGNlZTYzM2Q0NmU5NjEwYTAwZTg1ZWNiYjU=
|
data/Gemfile.lock
CHANGED
@@ -50,7 +50,7 @@ module SimpleParams
|
|
50
50
|
def type_description
|
51
51
|
value = options[:type]
|
52
52
|
case value
|
53
|
-
when :string, :integer, :array, :hash
|
53
|
+
when :string, :integer, :array, :hash, :object
|
54
54
|
"#{value.to_s.capitalize.constantize}"
|
55
55
|
when 'String', 'Integer', 'Array', 'Hash'
|
56
56
|
"#{value}"
|
@@ -13,7 +13,8 @@ module SimpleParams
|
|
13
13
|
float: Float,
|
14
14
|
boolean: Axiom::Types::Boolean, # See note on Virtus
|
15
15
|
array: Array,
|
16
|
-
hash: Hash
|
16
|
+
hash: Hash,
|
17
|
+
object: Object
|
17
18
|
}
|
18
19
|
|
19
20
|
attr_reader :parent
|
@@ -29,7 +30,8 @@ module SimpleParams
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def raw_value
|
32
|
-
@value.
|
33
|
+
empty = @value.nil? || (@value.is_a?(String) && @value.blank?)
|
34
|
+
empty ? default : @value
|
33
35
|
end
|
34
36
|
|
35
37
|
def value
|
data/lib/simple_params/params.rb
CHANGED
data/spec/acceptance_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class AcceptanceParams < SimpleParams::Params
|
4
|
+
param :reference, type: :object, optional: true
|
4
5
|
param :name
|
5
6
|
param :age, type: :integer, optional: true
|
6
7
|
param :color, default: "red", validations: { inclusion: { in: ["red", "green"] }}
|
@@ -17,6 +18,14 @@ describe SimpleParams::Params do
|
|
17
18
|
describe "accessors", accessors: true do
|
18
19
|
let(:params) { AcceptanceParams.new }
|
19
20
|
|
21
|
+
it "has getter and setter methods for object param", failing: true do
|
22
|
+
params.should respond_to(:reference)
|
23
|
+
params.reference.should be_nil
|
24
|
+
new_object = OpenStruct.new(count: 4)
|
25
|
+
params.reference = new_object
|
26
|
+
params.reference.should eq(new_object)
|
27
|
+
end
|
28
|
+
|
20
29
|
it "has getter and setter methods for required param" do
|
21
30
|
params.should respond_to(:name)
|
22
31
|
params.name.should be_nil
|
@@ -51,7 +60,7 @@ describe SimpleParams::Params do
|
|
51
60
|
describe "attributes", attributes: true do
|
52
61
|
it "returns array of attribute symbols" do
|
53
62
|
params = AcceptanceParams.new
|
54
|
-
params.attributes.should eq([:name, :age, :color, :address])
|
63
|
+
params.attributes.should eq([:reference, :name, :age, :color, :address])
|
55
64
|
end
|
56
65
|
end
|
57
66
|
|
@@ -148,6 +157,7 @@ describe SimpleParams::Params do
|
|
148
157
|
it "generates valida api_pie documentation" do
|
149
158
|
documentation = AcceptanceParams.api_pie_documentation
|
150
159
|
api_docs = <<-API_PIE_DOCS
|
160
|
+
param:reference, Object, desc:''
|
151
161
|
param :name, String, desc: '', required: true
|
152
162
|
param :age, Integer, desc: ''
|
153
163
|
param :color, String, desc: '', required: true
|
data/spec/attribute_spec.rb
CHANGED
@@ -89,6 +89,16 @@ describe SimpleParams::Attribute do
|
|
89
89
|
model.value.should be_falsey
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
93
|
+
context "with :object type" do
|
94
|
+
let(:model) { described_class.new(house, "color", { type: :object })}
|
95
|
+
|
96
|
+
it "coerces values into Object" do
|
97
|
+
other_house = House.new
|
98
|
+
model.value = other_house
|
99
|
+
model.value.should eq(other_house)
|
100
|
+
end
|
101
|
+
end
|
92
102
|
end
|
93
103
|
|
94
104
|
describe "defaults" do
|