Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rails_param
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
ikcrm_common
rails_param
Commits
528e7f04
Commit
528e7f04
authored
Sep 02, 2015
by
PiYa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use check_param_presence? method to check default param
parent
8f3c9b43
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
lib/rails_param/param.rb
+6
-3
No files found.
lib/rails_param/param.rb
View file @
528e7f04
...
@@ -15,12 +15,11 @@ module RailsParam
...
@@ -15,12 +15,11 @@ module RailsParam
def
param!
(
name
,
type
,
options
=
{},
&
block
)
def
param!
(
name
,
type
,
options
=
{},
&
block
)
name
=
name
.
to_s
unless
name
.
is_a?
Integer
# keep index for validating elements
name
=
name
.
to_s
unless
name
.
is_a?
Integer
# keep index for validating elements
return
unless
params
.
member?
(
name
)
||
check_param_presence?
(
options
[
:default
])
||
options
[
:required
]
return
unless
params
.
member?
(
name
)
||
(
not
options
[
:default
].
nil?
)
||
options
[
:required
]
begin
begin
params
[
name
]
=
coerce
(
params
[
name
],
type
,
options
)
params
[
name
]
=
coerce
(
params
[
name
],
type
,
options
)
params
[
name
]
=
(
options
[
:default
].
call
if
options
[
:default
].
respond_to?
(
:call
))
||
options
[
:default
]
if
params
[
name
].
nil?
and
(
not
options
[
:default
].
nil?
)
params
[
name
]
=
(
options
[
:default
].
call
if
options
[
:default
].
respond_to?
(
:call
))
||
options
[
:default
]
if
params
[
name
].
nil?
and
check_param_presence?
(
options
[
:default
]
)
params
[
name
]
=
options
[
:transform
].
to_proc
.
call
(
params
[
name
])
if
params
[
name
]
and
options
[
:transform
]
params
[
name
]
=
options
[
:transform
].
to_proc
.
call
(
params
[
name
])
if
params
[
name
]
and
options
[
:transform
]
validate!
(
params
[
name
],
options
)
validate!
(
params
[
name
],
options
)
...
@@ -66,6 +65,10 @@ module RailsParam
...
@@ -66,6 +65,10 @@ module RailsParam
private
private
def
check_param_presence?
param
not
param
.
nil?
end
def
recurse
(
params
,
index
=
nil
)
def
recurse
(
params
,
index
=
nil
)
raise
InvalidParameterError
,
'no block given'
unless
block_given?
raise
InvalidParameterError
,
'no block given'
unless
block_given?
controller
=
RailsParam
::
Param
::
MockController
.
new
controller
=
RailsParam
::
Param
::
MockController
.
new
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment