Module: StateManager::Adapters::Base::ClassMethods

Included in:
StateManager::Adapters::Base
Defined in:
lib/state_manager/adapters/base.rb

Instance Method Summary collapse

Instance Method Details

#adapter_nameObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


35
36
37
# File 'lib/state_manager/adapters/base.rb', line 35

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

#matching_ancestorsObject

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