Sha256: 1c2d0ab0897790327cf2e9660cb5d3cc23d6c5fc827684c10903508c758dd77b

Contents?: true

Size: 1.27 KB

Versions: 12

Compression:

Stored size: 1.27 KB

Contents

module Dugway
  module Drops
    class BaseDrop < Liquid::Drop
      attr_reader :source
      attr_reader :request
      attr_reader :params

      def initialize(source=nil)
        @source = source
      end

      def context=(current_context)
        @request = current_context.registers[:request]
        @params = current_context.registers[:params]
        super
      end

      def store
        Dugway.store
      end

      def theme
        Dugway.theme
      end

      def cart
        Dugway.cart
      end

      def before_method(method_or_key)
        if respond_to?(method_or_key)
          # don't do anything, just let it default here
        elsif source.respond_to?(method_or_key)
          return source.send(method_or_key)
        elsif source.respond_to?('has_key?') && source.has_key?(method_or_key)
          return source[method_or_key]
        elsif source.is_a?(Array) && source.first.has_key?('permalink')
          for item in source
            return item if item['permalink'] == method_or_key.to_s
          end
        end

        nil
      end

      def method_missing(method, *args, &block)
        before_method(method.to_s)
      end

      def errors
        @context['errors']
      end

      def error(msg)
        errors << msg
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dugway-1.0.14 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.13 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.12 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.10 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.9 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.8 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.7 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.6 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.5 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.4 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.3 lib/dugway/liquid/drops/base_drop.rb
dugway-1.0.2 lib/dugway/liquid/drops/base_drop.rb