Module: Statelogic::Util

Defined in:
lib/statelogic/activerecord.rb

Class Method Summary collapse

Class Method Details

.debug(msg = nil, &block) ⇒ Object



5
6
7
# File 'lib/statelogic/activerecord.rb', line 5

def self.debug(msg = nil, &block)
  ::ActiveRecord::Base.logger.debug(msg, &block) if ::ActiveRecord::Base.logger
end

.defmethod(cls, name, meta = false, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/statelogic/activerecord.rb', line 13

def self.defmethod(cls, name, meta = false, &block)
  c = meta ? cls.metaclass : cls
  unless c.method_defined?(name)
    c.send(:define_method, name, &block)
    debug { "Statelogic created #{meta ? 'class' : 'instance'} method #{name} on #{cls.name}." }
  else
    warn { "Statelogic won't override #{meta ? 'class' : 'instance'} method #{name} already defined on #{cls.name}." }
    nil
  end
end

.warn(msg = nil, &block) ⇒ Object



9
10
11
# File 'lib/statelogic/activerecord.rb', line 9

def self.warn(msg = nil, &block)
  ::ActiveRecord::Base.logger.warn(msg, &block) if ::ActiveRecord::Base.logger
end