Sha256: 18c69918c84e50a6f0e824c49a02f0267829c0ab2d55f7063ddb7b575e7efa58
Contents?: true
Size: 524 Bytes
Versions: 2
Compression:
Stored size: 524 Bytes
Contents
Crystal::AbstractController::ClassMethods.class_eval do def prepare_model aclass, opt = {} id = opt.delete(:id) || :id # variable = opt.delete(:variable) || aclass.model_name.underscore opt.must.include :variable variable = opt.delete(:variable) finder = opt.delete(:finder) || :find! method = "prepare_#{variable}" 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 |
---|---|
crystal_ext-0.0.5 | lib/crystal_ext/prepare_model.rb |
crystal_ext-0.0.4 | lib/crystal_ext/prepare_model.rb |