Module: StateManager::Adapters::Base::ClassMethods
- Included in:
- StateManager::Adapters::Base
- Defined in:
- lib/state_manager/adapters/base.rb
Instance Method Summary collapse
-
#adapter_name ⇒ Object
The name of the adapter.
-
#available? ⇒ Boolean
Whether this adapter is available for the current library.
-
#matches?(klass) ⇒ Boolean
Whether the adapter should be used for the given class.
-
#matches_ancestors?(ancestors) ⇒ Boolean
Whether the adapter should be used for the given list of ancestors.
-
#matching_ancestors ⇒ Object
The list of ancestor names that cause this adapter to matched.
Instance Method Details
#adapter_name ⇒ Object
The name of the adapter
7 8 9 10 11 12 13 14 15 |
# File 'lib/state_manager/adapters/base.rb', line 7 def adapter_name @adapter_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 |
#available? ⇒ Boolean
Whether this adapter is available for the current library. This is only true if the ORM that the adapter is for is currently defined.
20 21 22 |
# File 'lib/state_manager/adapters/base.rb', line 20 def available? matching_ancestors.any? && Object.const_defined?(matching_ancestors[0].split('::')[0]) end |
#matches?(klass) ⇒ Boolean
Whether the adapter should be used for the given class.
30 31 32 |
# File 'lib/state_manager/adapters/base.rb', line 30 def matches?(klass) matches_ancestors?(klass.ancestors.map {|ancestor| ancestor.name}) end |
#matches_ancestors?(ancestors) ⇒ Boolean
Whether the adapter should be used for the given list of ancestors.
35 36 37 |
# File 'lib/state_manager/adapters/base.rb', line 35 def matches_ancestors?(ancestors) (ancestors & matching_ancestors).any? end |
#matching_ancestors ⇒ Object
The list of ancestor names that cause this adapter to matched.
25 26 27 |
# File 'lib/state_manager/adapters/base.rb', line 25 def matching_ancestors [] end |