Class: Statesman::Adapters::MongoidQueries::ClassMethods

Inherits:
Module
  • Object
show all
Defined in:
lib/statesman/adapters/mongoid_queries.rb

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ ClassMethods

Returns a new instance of ClassMethods.



39
40
41
# File 'lib/statesman/adapters/mongoid_queries.rb', line 39

def initialize(**args)
  @args = args
end

Instance Method Details

#included(base) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/statesman/adapters/mongoid_queries.rb', line 43

def included(base)
  ensure_inheritance(base)

  query_builder = QueryBuilder.new(base, **@args)

  base.define_singleton_method(:most_recent_transition_join) do
    puts <<~STUB_NOTE
      \e[1;33mmost_recent_transition_join\e[0;33m is a stub to provide feature-parity
      with the default ActiveRecord adapters, Mongoid doesn't support joins\e[0m
    STUB_NOTE
    self
  end

  define_in_state(base, query_builder)
  define_not_in_state(base, query_builder)

  define_method(:reload) do |*a|
    instance = super(*a)
    if instance.respond_to?(:state_machine, true)
      instance.state_machine.reset
    end
    instance
  end
end