Sha256: e754ffc15cbb9e4792e1fe0d84b7706114ffd59c9f2ab3c5fe78d9b1ed13019f

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

require 'hashie'
require 'erb'

module Omnitest
  module Core
    class Dash < Hashie::Dash
      include Hashie::Extensions::Coercion

      def initialize(hash = {})
        super Omnitest::Core::Util.symbolized_hash(hash)
      end

      # @api private
      # @!macro [attach] field
      #   @!attribute [rw] $1
      #     Attribute $1. $3
      #     @return [$2]
      # Defines a typed attribute on a class.
      def self.field(name, type, opts = {})
        property name, opts
        coerce_key name, type
      end

      # @api private
      # @!macro [attach] required_field
      #   @!attribute [rw] $1
      #     **Required** Attribute $1. $3
      #     @return [$2]
      # Defines a required, typed attribute on a class.
      def self.required_field(name, type, opts = {})
        opts[:required] = true
        field(name, type, opts)
      end

      module Loadable
        include Core::DefaultLogger
        def from_yaml(yaml_file)
          logger.debug "Loading #{yaml_file}"
          raw_content = File.read(yaml_file)
          processed_content = ERB.new(raw_content).result
          data = YAML.load processed_content
          new data
        end
      end
    end

    class Mash < Hashie::Mash
      include Hashie::Extensions::Coercion
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
omnitest-core-0.0.3 lib/omnitest/core/hashie.rb
omnitest-core-0.0.2 lib/omnitest/core/hashie.rb
omnitest-core-0.0.1 lib/omnitest/core/hashie.rb