Sha256: f6555769dbe46304e35c93627ea4b7ab1ba326ef0794f2efc713d4f9637598b4

Contents?: true

Size: 710 Bytes

Versions: 11

Compression:

Stored size: 710 Bytes

Contents

require 'lotus/utils/kernel'

module Lotus
  module Config
    # Define a mapping for Lotus::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

11 entries across 11 versions & 1 rubygems

Version Path
lotusrb-0.6.1 lib/lotus/config/mapper.rb
lotusrb-0.6.0 lib/lotus/config/mapper.rb
lotusrb-0.5.0 lib/lotus/config/mapper.rb
lotusrb-0.4.1 lib/lotus/config/mapper.rb
lotusrb-0.4.0 lib/lotus/config/mapper.rb
lotusrb-0.3.2 lib/lotus/config/mapper.rb
lotusrb-0.3.1 lib/lotus/config/mapper.rb
lotusrb-0.3.0 lib/lotus/config/mapper.rb
lotusrb-0.2.1 lib/lotus/config/mapper.rb
lotusrb-0.2.0 lib/lotus/config/mapper.rb
lotusrb-0.1.0 lib/lotus/config/mapper.rb