simple_params 0.0.2.pre8 → 0.0.2.pre9
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/README.md +41 -7
- data/lib/simple_params/params.rb +18 -1
- data/lib/simple_params/version.rb +1 -1
- data/spec/acceptance_spec.rb +20 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDY4OWUwYTdkOTc5NmYwYjZlZjdjMmY3YzU4MWRkYWQ5ZGZlZWRhNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDI5OGEzYjEzODU3ODJmNDMxMmExYzc1NGZlOGEwZmYyODUxNjg2Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTY3YTQzMTY2YzRlYTE0ZGRlM2FkNDJmNDdlYzI2Zjc5Mjg0NzQ5OWRlODE0
|
10
|
+
NTAzM2NlYWE0NDFiZWYyY2M5NGUyNmYxOWI4ZDhhN2VmOTAxNzdkNTQ0MTYw
|
11
|
+
NjNlNzE3YmFlNmM3NDkwMTQ1ZmFhZDQxMGRmM2ZjOTgxMTBhMTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTBlZTQ0YTQ4NjNhODg1ZTE3NjJkY2E2ODAyOTRjZjQ5ZDE5NWI3ZjIxM2Nh
|
14
|
+
Mjg0MjdkNzI1MzRmZGRhNzhmYjZiNTk3YTZiOWUwNzg0N2NhMDQ2OWMxMjdi
|
15
|
+
NjU5NDg0YTU4NDQ3OGE1YjYxNGJmMGExYjkyNTdmNmUxMjAwYzA=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -88,12 +88,12 @@ params = MyParams.new(
|
|
88
88
|
)
|
89
89
|
|
90
90
|
params.valid? #=> false
|
91
|
-
params.errors[:name] #=> ["can't be blank"]
|
92
|
-
params.errors[:address][:street] #=> ["can't be blank"]
|
93
|
-
params.address.errors[:street] #=> ["can't be blank"]
|
91
|
+
params.errors[:name] #=> ["can't be blank"]
|
92
|
+
params.errors[:address][:street] #=> ["can't be blank"]
|
93
|
+
params.address.errors[:street] #=> ["can't be blank"]
|
94
94
|
|
95
|
-
params.errors.as_json #=> {:name=>["can't be blank"], :address=>{:street=>["can't be blank"]}}
|
96
|
-
params.address.errors.as_json #=> {:street=>["can't be blank"]}
|
95
|
+
params.errors.as_json #=> {:name=>["can't be blank"], :address=>{:street=>["can't be blank"]}}
|
96
|
+
params.address.errors.as_json #=> {:street=>["can't be blank"]}
|
97
97
|
```
|
98
98
|
|
99
99
|
## Defaults
|
@@ -138,7 +138,7 @@ params = CoercionParams.new(name: "Bob", age: "21", date_of_birth: "June 1st, 19
|
|
138
138
|
params.name #=> "Bob"
|
139
139
|
params.age #=> 21
|
140
140
|
params.date_of_birth #=> #<Date: 1980-06-01>
|
141
|
-
params.pocket_change #=> #<BigDecimal:89ed240,'0.235E1',18(18)>
|
141
|
+
params.pocket_change #=> #<BigDecimal:89ed240,'0.235E1',18(18)>
|
142
142
|
```
|
143
143
|
|
144
144
|
SimpleParams also provide helper methods for implicitly specifying the type, if you prefer that syntax. Here is the same class as above, but redefined with these helper methods.
|
@@ -192,6 +192,40 @@ params.dog.name #=> "Bailey"
|
|
192
192
|
params.dog.breed #=> "Shiba Inu"
|
193
193
|
```
|
194
194
|
|
195
|
+
# ApiPie Documentation
|
196
|
+
|
197
|
+
If your project is using [apipie-rails](http://example.com/ "apipie-rails"),
|
198
|
+
then SimpleParams is able to automatically generate the documentation markup
|
199
|
+
for apipie.
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
api :POST, '/objects', "Create a object"
|
203
|
+
eval(CreateObjectParams.api_pie_documentation)
|
204
|
+
```
|
205
|
+
|
206
|
+
Note that in your SimpleParams class you can specify a few options on how the markup will be
|
207
|
+
created.
|
208
|
+
|
209
|
+
They include:
|
210
|
+
```ruby
|
211
|
+
document: false # Will not document this parameter. Default is true
|
212
|
+
optional: true # This parameter is not required. Default is false
|
213
|
+
desc: 'description of parameter' # Default is blank
|
214
|
+
```
|
215
|
+
|
216
|
+
Example:
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
class CreateObjectParams < SimpleParams::Params
|
220
|
+
param :user, type: User, document: false
|
221
|
+
param :name, type: :string, desc: 'Name of object', validations: { presence: true }
|
222
|
+
|
223
|
+
nested_hash :other_object do
|
224
|
+
param :color, optional: true, validations: { presence: true }
|
225
|
+
param :size, desc: 'Size of object', 'validations: { presence: true }
|
226
|
+
end
|
227
|
+
end
|
228
|
+
```
|
195
229
|
|
196
230
|
## Contributing
|
197
231
|
|
@@ -199,4 +233,4 @@ params.dog.breed #=> "Shiba Inu"
|
|
199
233
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
200
234
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
201
235
|
4. Push to the branch (`git push origin my-new-feature`)
|
202
|
-
5. Create new Pull Request
|
236
|
+
5. Create new Pull Request
|
data/lib/simple_params/params.rb
CHANGED
@@ -132,6 +132,12 @@ module SimpleParams
|
|
132
132
|
(defined_attributes.keys + nested_hashes.keys).flatten
|
133
133
|
end
|
134
134
|
|
135
|
+
def original_params
|
136
|
+
@original_params ||= {}
|
137
|
+
end
|
138
|
+
alias_method :original_hash, :original_params
|
139
|
+
alias_method :raw_params, :original_params
|
140
|
+
|
135
141
|
# Overriding this method to allow for non-strict enforcement!
|
136
142
|
def method_missing(method_name, *arguments, &block)
|
137
143
|
if strict_enforcement?
|
@@ -171,7 +177,18 @@ module SimpleParams
|
|
171
177
|
end
|
172
178
|
|
173
179
|
def hash_to_symbolized_hash(hash)
|
174
|
-
hash.inject({}){|
|
180
|
+
hash.inject({}){|result, (key, value)|
|
181
|
+
new_key = case key
|
182
|
+
when String then key.to_sym
|
183
|
+
else key
|
184
|
+
end
|
185
|
+
new_value = case value
|
186
|
+
when Hash then hash_to_symbolized_hash(value)
|
187
|
+
else value
|
188
|
+
end
|
189
|
+
result[new_key] = new_value
|
190
|
+
result
|
191
|
+
}
|
175
192
|
end
|
176
193
|
|
177
194
|
def defined_attributes
|
data/spec/acceptance_spec.rb
CHANGED
@@ -15,10 +15,29 @@ class AcceptanceParams < SimpleParams::Params
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe SimpleParams::Params do
|
18
|
+
describe "original_params", original_params: true do
|
19
|
+
it "returns symbolized params hash" do
|
20
|
+
params = AcceptanceParams.new(name: "Tom", address: { "street" => "1 Main St."} )
|
21
|
+
params.original_params.should eq({
|
22
|
+
name: "Tom",
|
23
|
+
address: {
|
24
|
+
street: "1 Main St."
|
25
|
+
}
|
26
|
+
})
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns symbolized params for nested_hash" do
|
30
|
+
params = AcceptanceParams.new(name: "Tom", address: { "street" => "1 Main St."} )
|
31
|
+
params.address.original_params.should eq({
|
32
|
+
street: "1 Main St."
|
33
|
+
})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
18
37
|
describe "accessors", accessors: true do
|
19
38
|
let(:params) { AcceptanceParams.new }
|
20
39
|
|
21
|
-
it "has getter and setter methods for object param"
|
40
|
+
it "has getter and setter methods for object param" do
|
22
41
|
params.should respond_to(:reference)
|
23
42
|
params.reference.should be_nil
|
24
43
|
new_object = OpenStruct.new(count: 4)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2.
|
4
|
+
version: 0.0.2.pre9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brycesenz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|