Module: Garcon::Resource::Validations::ClassMethods

Included in:
Garcon::Resource::Validations
Defined in:
lib/garcon/chef/validations.rb

Instance Method Summary collapse

Instance Method Details

#absolute_uri?(source) ⇒ Boolean

Boolean, true if source is an absolute URI, false otherwise.

Parameters:

Returns:



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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Hook called when module is included.

Parameters:

  • descendant (Module)

    The including module or class.

Returns:

  • (self)


67
68
69
70
# File 'lib/garcon/chef/validations.rb', line 67

def included(descendant)
  super
  descendant.extend ClassMethods
end

#source_callbacksProc

Callback for source URL validation.

Returns:

  • (Proc)


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.

Parameters:

Returns:



43
44
45
# File 'lib/garcon/chef/validations.rb', line 43

def valid_source?(source)
  absolute_uri?(source) ? true : ::File.exist?(source)
end