Module: Garcon::Resource::Validations::ClassMethods
- Included in:
- Garcon::Resource::Validations
- Defined in:
- lib/garcon/chef/validations.rb
Instance Method Summary collapse
-
#absolute_uri?(source) ⇒ Boolean
Boolean, true if source is an absolute URI, false otherwise.
-
#included(descendant) ⇒ self
Hook called when module is included, extends a descendant with class and instance methods.
-
#source_callbacks ⇒ Proc
Callback for source URL validation.
-
#valid_source?(source) ⇒ Boolean
Validate that the source attribute is an absolute URI or file and not an not empty string.
Instance Method Details
#absolute_uri?(source) ⇒ Boolean
Boolean, true if source is an absolute URI, false otherwise.
53 54 55 56 57 |
# File 'lib/garcon/chef/validations.rb', line 53 def absolute_uri?(source) source =~ URI::ABS_URI && URI.parse(source).absolute? rescue URI::InvalidURIError false end |
#included(descendant) ⇒ self
Hook called when module is included, extends a descendant with class and instance methods.
67 68 69 70 |
# File 'lib/garcon/chef/validations.rb', line 67 def included(descendant) super descendant.extend ClassMethods end |
#source_callbacks ⇒ Proc
Callback for source URL validation.
32 33 34 |
# File 'lib/garcon/chef/validations.rb', line 32 def source_callbacks { 'Source must be an absolute URI' => ->(src) { valid_source?(src) }} end |
#valid_source?(source) ⇒ Boolean
Validate that the source attribute is an absolute URI or file and not an not empty string.
43 44 45 |
# File 'lib/garcon/chef/validations.rb', line 43 def valid_source?(source) absolute_uri?(source) ? true : ::File.exist?(source) end |