module ErpTechSvcs::Extensions::ActiveRecord::ScopedBy::ClassMethods
Public Instance Methods
add_scoped_by(attr_name=:scoped_by)
click to toggle source
# File lib/erp_tech_svcs/extensions/active_record/scoped_by.rb, line 19 def add_scoped_by(attr_name=:scoped_by) # serialize Scope attributes is_json attr_name extend SingletonMethods include InstanceMethods # create method to retrieve scoped_by attribute name define_singleton_method("retrieve_scoped_by_name") do attr_name end # create method to initialize the json field with an empty hash define_method("initialize_#{attr_name}_scoped_by_json") do if self.new_record? send("#{attr_name}=", {}) end end after_initialize "initialize_#{attr_name}_scoped_by_json" end