Module: StateMachines::Integrations::Base::ClassMethods
- Defined in:
- lib/state_machines/integrations/base.rb
Instance Attribute Summary collapse
-
#defaults ⇒ Object
readonly
The default options to use for state machines using this integration.
Instance Method Summary collapse
-
#integration_name ⇒ Object
The name of the integration.
-
#matches?(klass) ⇒ Boolean
Whether the integration should be used for the given class.
-
#matches_ancestors?(ancestors) ⇒ Boolean
Whether the integration should be used for the given list of ancestors.
-
#matching_ancestors ⇒ Object
The list of ancestor names that cause this integration to matched.
Instance Attribute Details
#defaults ⇒ Object (readonly)
The default options to use for state machines using this integration
9 10 11 |
# File 'lib/state_machines/integrations/base.rb', line 9 def defaults @defaults end |
Instance Method Details
#integration_name ⇒ Object
The name of the integration
12 13 14 15 16 17 18 19 20 |
# File 'lib/state_machines/integrations/base.rb', line 12 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.
28 29 30 |
# File 'lib/state_machines/integrations/base.rb', line 28 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.
33 34 35 |
# File 'lib/state_machines/integrations/base.rb', line 33 def matches_ancestors?(ancestors) (ancestors & matching_ancestors).any? end |
#matching_ancestors ⇒ Object
The list of ancestor names that cause this integration to matched.
23 24 25 |
# File 'lib/state_machines/integrations/base.rb', line 23 def matching_ancestors [] end |