module Behaveable::ResourceFinder

Public Instance Methods

behaveable() click to toggle source

Get the behaveable object.

Returns

  • ActiveRecord::Model - Behaveable instance object.

# File lib/behaveable/resource_finder.rb, line 8
def behaveable
  klass, param = behaveable_class
  klass.find(params[param.to_sym]) if klass
end

Private Instance Methods

behaveable_class() click to toggle source

Lookup behaveable class.

Returns

  • Response - Behaveable class object or nil if not found.

# File lib/behaveable/resource_finder.rb, line 19
def behaveable_class
  params.each do |name, _value|
    if name =~ /(.+)_id$/
      model = name.match(%r{([^\/.]*)_id$})
      return model[1].classify.constantize, name
    end
  end
  nil
end