Sha256: 08673bf2b0ab678e6f6b6066d10f7a66c5ecdd8021b025e996cd5914ac2e2639

Contents?: true

Size: 904 Bytes

Versions: 1

Compression:

Stored size: 904 Bytes

Contents

require 'chozo/varia_model'

module Chozo
  module Config
    # @author Jamie Winsor <jamie@vialstudios.com>
    # @api private
    class Abstract
      extend Forwardable
      include VariaModel
      
      attr_accessor :path

      def_delegator :to_hash, :slice
      def_delegator :to_hash, :slice!
      def_delegator :to_hash, :extract!

      # @param [String] path
      # @param [Hash] attributes
      def initialize(path = nil, attributes = {})
        @path = File.expand_path(path) if path

        mass_assign(attributes)
      end

      def [](key)
        self.attributes[key]
      end

      def []=(key, value)
        self.attributes[key] = value
      end

      def to_hash
        self.attributes.to_hash.deep_symbolize_keys
      end

      protected

        def mass_assign(new_attributes = {})
          attributes.deep_merge!(new_attributes)
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chozo-0.3.0 lib/chozo/config/abstract.rb