Skip to content

(MODULES-560) Add new functions validate_numeric() and validate_integer().#375

Merged
hunner merged 2 commits intopuppetlabs:masterfrom
poikilotherm:feature/master/validate_integer_and_numeric
Mar 5, 2015
Merged

(MODULES-560) Add new functions validate_numeric() and validate_integer().#375
hunner merged 2 commits intopuppetlabs:masterfrom
poikilotherm:feature/master/validate_integer_and_numeric

Conversation

@poikilotherm
Copy link
Copy Markdown
Contributor

I saw MODULES-560 on Jira (https://tickets.puppetlabs.com/browse/MODULES-560) and had a need for it (check ports easily in a manifest), so I implemented it.

Added rspec unit tests, too.
Added necessary stuff to README.markdown, too.

Would be glad, if this gets merged... :) Thanks!

@ckaenzig
Copy link
Copy Markdown

ckaenzig commented Dec 5, 2014

👍 I was just browsing the module's documentation looking for a validate_int(eger) function :) !

@poikilotherm
Copy link
Copy Markdown
Contributor Author

I missed to write an acceptance test. Will do so later and push it.

@poikilotherm poikilotherm changed the title Add new functions validate_numeric() and validate_integer(). (MODULES-560) Add new functions validate_numeric() and validate_integer(). Dec 18, 2014
@cyberious
Copy link
Copy Markdown
Contributor

With the future parse and types in the next version, what is this accomplishing that you can't with validate_re and a regex like '^-?\d+.?\d$'
Just trying to understand use case.

@joshcooper
Copy link
Copy Markdown
Contributor

/cc @hlindberg

@hlindberg
Copy link
Copy Markdown
Contributor

With the new type system in Puppet 4.0 (and in future parser in 3.x) there is support for checking not only type but also the values of types. As an example, for integers (and floats) the type can be expressed as a range and the type can be combined with Optional (if an undef value is acceptable). Further you can use the scanf function to convert string representations to values (and handle failure). Types can be combined to express things like - Array of integers in a range etc. Type checking is automatic if parameter are declared with type, and there is an assert_type function that can be used for manual type checking.

IMO we already have far too many "is_xxx" and "validate_xxx" functions in standard lib and we are about to deprecate and update these functions for puppet 4. Suggest sharing this validate_numeric function in a separate module for older puppet versions.

@poikilotherm
Copy link
Copy Markdown
Contributor Author

Right, didn't have the new Puppet 4 stuff on the radar, but wanted to be able to do things now, still using Puppet 3.x

Is there already such a module like you suggested? This seems to be a good plan...

@hlindberg
Copy link
Copy Markdown
Contributor

There is no such module (collection of 3x, new, but soon to be deprecated functions) - suggest you create your own.

hunner added a commit that referenced this pull request Mar 5, 2015
…eger_and_numeric

(MODULES-560) Add new functions validate_numeric() and validate_integer().
@hunner hunner merged commit 41965fd into puppetlabs:master Mar 5, 2015
@hlindberg
Copy link
Copy Markdown
Contributor

I had a knee-jerk reaction and posted something that was not right. I deleted that comment. Sorry about the noise, should have read more carefully.

@poikilotherm
Copy link
Copy Markdown
Contributor Author

Ego te absolvo.

Thanks for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants