Sha256: 2027f4b6eed48b476c9b26cfb22603e2b801c0b0f269d1d2f3667966e35bf893

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Meta2
  module Strategies
    class ActiveRecord
      include Meta2::Strategies

      def detect
        absorber = Meta2::Absorber.new
        absorber.formats  = get_section :formats
        absorber.defaults = get_section :defaults

        retrieve_parts do |path|
          settings = parts.where path: path
          section = settings.find_each.map do |setting|
            [setting.name.to_sym, setting.value]
          end
          next nil if section.blank?
          absorber.parts = Hash[*section.flatten]
        end
        absorber.parts ||= Hash.new

        absorber
      end

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


      private

      def parts
        targets.where section: :parts
      end

      def get_section(namespace)
        section = targets.where(section: namespace).find_each.map do |setting|
          [setting.name.to_sym, setting.value]
        end
        section = Hash[*section.flatten]

        default_formats.merge section
      end

      def targets
        Meta2::Models::MetaSetting.where app_name: @config[:assign_name]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
meta2-0.0.1 lib/meta2/strategies/active_record.rb