Sha256: 43399dfd20fafdae821fdc00d2e81557bfb6ebec4d5b439a2a89d9155c5767dc

Contents?: true

Size: 466 Bytes

Versions: 2

Compression:

Stored size: 466 Bytes

Contents

Rad::Controller::Abstract::ClassMethods.class_eval do
  def prepare_model aclass, opt = {}
    opt = opt.symbolize_keys
    id = opt.delete(:id) || :id
    variable = opt.delete(:variable) || aclass.alias.underscore

    finder = opt.delete(:finder) || :find!

    method = "prepare_#{variable}".to_sym
    define_method method do
      model = aclass.send finder, params[id]
      instance_variable_set "@#{variable}", model
    end
    before method, opt
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rad_kit-0.0.10 lib/kit/misc/prepare_model.rb
rad_kit-0.0.9 lib/kit/misc/prepare_model.rb