Sha256: caf752590d1c0ac795fae8a3a1c3ffc8d80215a1de1ffb61481e486e0a5f3db1

Contents?: true

Size: 713 Bytes

Versions: 5

Compression:

Stored size: 713 Bytes

Contents

require 'hanami/utils/kernel'

module Hanami
  module Config
    # Define a mapping for Hanami::Model
    #
    # @since 0.1.0
    # @api private
    class Mapper
      EXTNAME = '.rb'

      def initialize(root, path, &blk)
        @path, @blk = path, blk
        @path = root.join(path) if root && path
      end

      def to_proc
        return @blk if @blk

        code = realpath.read
        Proc.new { eval(code) }
      end

      private
      def realpath
        Utils::Kernel.Pathname("#{ @path }#{ EXTNAME }").realpath
      rescue Errno::ENOENT
        raise ArgumentError, error_message
      end

      def error_message
        'You must specify a block or a file.'
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hanami-0.8.0 lib/hanami/config/mapper.rb
hanami-0.7.3 lib/hanami/config/mapper.rb
hanami-0.7.2 lib/hanami/config/mapper.rb
hanami-0.7.1 lib/hanami/config/mapper.rb
hanami-0.7.0 lib/hanami/config/mapper.rb