Sha256: b0c310604ceb179b1ea5d62678c30b7984d985167ac7a546e8a18df31872543d

Contents?: true

Size: 828 Bytes

Versions: 2

Compression:

Stored size: 828 Bytes

Contents

module Meta2
  module Strategies
    attr_reader :options, :config, :formats

    def initialize(options)
      @options  = options
      @config   = Meta2.config
    end

    def detect
      raise "`detect` method Must be need to overriden"
    end


    protected

    def retrieve_parts
      @options[:prefixes].detect do |prefix|
        path    = build_path prefix
        result  = yield path
        Meta2.debug "part path:#{path} #{result ? 'hit' : 'miss'}"
        result
      end
    end

    def build_path(prefix)
      path_prefix = prefix.gsub '/', '.'
      '%s.config.parts.%s.%s' % [
        @config.assign_name, path_prefix, @options[:template]
      ]
    end

    def default_formats
      hash = @config.columns.map do |column|
        [column, '%']
      end
      Hash[*hash.flatten]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
meta2-0.0.3 lib/meta2/strategies.rb
meta2-0.0.2 lib/meta2/strategies.rb