Module: StateMachines::Integrations::Base::ClassMethods

Defined in:
lib/state_machines/integrations/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultsObject (readonly)

The default options to use for state machines using this integration



7
8
9
# File 'lib/state_machines/integrations/base.rb', line 7

def defaults
  @defaults
end

Instance Method Details

#integration_nameObject

The name of the integration



10
11
12
13
14
15
16
17
18
# File 'lib/state_machines/integrations/base.rb', line 10

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

#matches?(klass) ⇒ Boolean

Whether the integration should be used for the given class.

Returns:

  • (Boolean)


26
27
28
# File 'lib/state_machines/integrations/base.rb', line 26

def matches?(klass)
  matching_ancestors.any? { |ancestor| klass <= ancestor }
end

#matches_ancestors?(ancestors) ⇒ Boolean

Whether the integration should be used for the given list of ancestors.

Returns:

  • (Boolean)


31
32
33
# File 'lib/state_machines/integrations/base.rb', line 31

def matches_ancestors?(ancestors)
  (ancestors & matching_ancestors).any?
end

#matching_ancestorsObject

The list of ancestor names that cause this integration to matched.



21
22
23
# File 'lib/state_machines/integrations/base.rb', line 21

def matching_ancestors
  []
end