Sha256: 9a73763a58042338a9129486c1b16a537501014e8d20c4525def17d79b082303

Contents?: true

Size: 1.35 KB

Versions: 17

Compression:

Stored size: 1.35 KB

Contents

module Shamu
  module Features
    module Conditions

      # Match against a custom method. Due to their dynamic nature, proc
      # conditions are much slower and should be reserved for only a few
      # features.
      #
      # The proc is specified in the configuration by class and method name like
      #
      # ```yaml
      # # features.yml
      # commerce:
      #   buy_now:
      #     select:
      #     - proc: Commerce::BuyNow#match?
      # ```
      #
      # Shamu will instantiate a new instance of the `Commerce::BuyNow` class
      # and invoke the `match?` method passing the current {Features::Context}.
      #
      # The custom proj will also have access to the current {Scorpion} if it
      # includes the {Scorpion::Object} mixin.
      class Proc < Conditions::Condition
        include Scorpion::Object

        # (see Condition#match?)
        def match?( context )
          instance( context ).send( proc_method, context, toggle )
        end

        private

          def instance( context )
            context.scorpion.fetch( proc_class )
          end

          def proc_class
            @proc_class ||= proc_config.first.constantize
          end

          def proc_method
            proc_config.last
          end

          def proc_config
            @proc_config ||= config.split( "#" )
          end

      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shamu-0.0.24 lib/shamu/features/conditions/proc.rb
shamu-0.0.21 lib/shamu/features/conditions/proc.rb
shamu-0.0.20 lib/shamu/features/conditions/proc.rb
shamu-0.0.19 lib/shamu/features/conditions/proc.rb
shamu-0.0.18 lib/shamu/features/conditions/proc.rb
shamu-0.0.17 lib/shamu/features/conditions/proc.rb
shamu-0.0.15 lib/shamu/features/conditions/proc.rb
shamu-0.0.14 lib/shamu/features/conditions/proc.rb
shamu-0.0.13 lib/shamu/features/conditions/proc.rb
shamu-0.0.11 lib/shamu/features/conditions/proc.rb
shamu-0.0.9 lib/shamu/features/conditions/proc.rb
shamu-0.0.8 lib/shamu/features/conditions/proc.rb
shamu-0.0.7 lib/shamu/features/conditions/proc.rb
shamu-0.0.5 lib/shamu/features/conditions/proc.rb
shamu-0.0.4 lib/shamu/features/conditions/proc.rb
shamu-0.0.3 lib/shamu/features/conditions/proc.rb
shamu-0.0.2 lib/shamu/features/conditions/proc.rb