Sha256: b533580e4832880870ccd039b07b7d3f57487c63033248fe0096de307a3e46a0

Contents?: true

Size: 925 Bytes

Versions: 1

Compression:

Stored size: 925 Bytes

Contents

module CheckMot

  class Resource
    def initialize(source_hash)
      @source_hash = source_hash
    end

    def respond_to_missing?(name, include_private = false)
      true
    end

    def method_missing(name, *args)
      resolved_attribute(name)
    end

    def inspect
      # prevents extraneous output in the console:
      to_s
    end

    private

    attr_reader :source_hash

    def resolved_attribute(name)
      resolved_attributes[name] ||= resolve_attribute(name, source_hash[name])
    end

    def resolved_attributes
      @_resolved_attributes ||= {}
    end

    def resolve_attribute(name, value)
      attribute = Attribute.resolve(name, value)

      case attribute
      when Array
        attribute.map { |value| resolve_attribute(name, value) }
      when Hash
        Resource.new(attribute)
      when Attribute
        attribute.value
      else
        value
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
check_mot-0.3.1 lib/check_mot/resource.rb