Sha256: 27b7e0bf4fc539ce83f6698f05e45b31a23f6c90c4b4254b9950d80c025b0c12

Contents?: true

Size: 1.24 KB

Versions: 11

Compression:

Stored size: 1.24 KB

Contents

module StateMachines
  module Integrations
    # Provides a set of base helpers for managing individual integrations
    module Base
      module ClassMethods
        # The default options to use for state machines using this integration
        attr_reader :defaults

        # The name of the integration
        def integration_name
          @integration_name ||= begin
            name = self.name.split('::').last
            name.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
            name.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
            name.downcase!
            name.to_sym
          end
        end

        # The list of ancestor names that cause this integration to matched.
        def matching_ancestors
          []
        end

        # Whether the integration should be used for the given class.
        def matches?(klass)
          matches_ancestors?(klass.ancestors.map { |ancestor| ancestor.name })
        end

        # Whether the integration should be used for the given list of ancestors.
        def matches_ancestors?(ancestors)
          (ancestors & matching_ancestors).any?
        end

      end

      extend ClassMethods

      def self.included(base) #:nodoc:
        base.class_eval { extend ClassMethods }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-0.2.2/lib/state_machines/integrations/base.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-0.2.2/lib/state_machines/integrations/base.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-0.2.2/lib/state_machines/integrations/base.rb
state_machines-0.4.0 lib/state_machines/integrations/base.rb
state_machines-0.3.0 lib/state_machines/integrations/base.rb
state_machines-0.2.2 lib/state_machines/integrations/base.rb
state_machines-0.2.1 lib/state_machines/integrations/base.rb
state_machines-0.2.0 lib/state_machines/integrations/base.rb
state_machines-0.1.4 lib/state_machines/integrations/base.rb
state_machines-0.1.3 lib/state_machines/integrations/base.rb
state_machines-0.1.2 lib/state_machines/integrations/base.rb