Sha256: 83a007b231c613ef09f9c7d5288bb6ad98ccc9f1a7d86ddee2513c5d5db5dadb

Contents?: true

Size: 549 Bytes

Versions: 14

Compression:

Stored size: 549 Bytes

Contents

module ChefAPI
  class Validator::Type < Validator::Base
    attr_reader :types

    #
    # Overload the super method to capture the type attribute in the options
    # hash.
    #
    def initialize(attribute, type)
      super
      @types = Array(type)
    end

    def validate(resource)
      value = resource._attributes[attribute]

      if value && !types.any? { |type| value.is_a?(type) }
        short_name = type.to_s.split('::').last
        resource.errors.add(attribute, "must be a kind of #{short_name}")
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
chef-infra-api-0.10.0 lib/chef-api/validators/type.rb
chef-api-0.10.0 lib/chef-api/validators/type.rb
chef-infra-api-0.9.1 lib/chef-api/validators/type.rb
chef-api-0.9.0 lib/chef-api/validators/type.rb
chef-api-0.8.0 lib/chef-api/validators/type.rb
chef-api-0.7.1 lib/chef-api/validators/type.rb
chef-api-0.7.0 lib/chef-api/validators/type.rb
chef-api-0.6.0 lib/chef-api/validators/type.rb
chef-api-0.5.0 lib/chef-api/validators/type.rb
chef-api-0.4.1 lib/chef-api/validators/type.rb
chef-api-0.4.0 lib/chef-api/validators/type.rb
chef-api-0.3.0 lib/chef-api/validators/type.rb
chef-api-0.2.1 lib/chef-api/validators/type.rb
chef-api-0.2.0 lib/chef-api/validators/type.rb