Module: Statesman::Adapters::MongoidQueries

Defined in:
lib/statesman/adapters/mongoid_queries.rb

Defined Under Namespace

Classes: ClassMethods, QueryBuilder

Class Method Summary collapse

Class Method Details

.[](**args) ⇒ Object



34
35
36
# File 'lib/statesman/adapters/mongoid_queries.rb', line 34

def self.[](**args)
  ClassMethods.new(**args)
end

.check_missing_methods!(base) ⇒ Object

Raises:

  • (NotImplementedError)


8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/statesman/adapters/mongoid_queries.rb', line 8

def self.check_missing_methods!(base)
  missing_methods = %i[transition_class initial_state].
    reject { |m| base.respond_to?(m) }
  return if missing_methods.none?

  raise NotImplementedError,
        "#{missing_methods.join(', ')} method(s) should be defined on " \
        "the model. Alternatively, use the new form of `include " \
        "Statesman::Adapters::MongoidQueries[" \
        "transition_class: MyTransition, " \
        "initial_state: :some_state]`"
end

.included(base) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/statesman/adapters/mongoid_queries.rb', line 21

def self.included(base)
  check_missing_methods!(base)

  base.include(
    ClassMethods.new(
      transition_class: base.transition_class,
      initial_state: base.initial_state,
      most_recent_transition_alias: base.try(:most_recent_transition_alias),
      transition_name: base.try(:transition_name),
    ),
  )
end