Skip to content

Instantly share code, notes, and snippets.

@swalberg
Created June 17, 2012 18:33
Show Gist options
  • Save swalberg/2945356 to your computer and use it in GitHub Desktop.
Save swalberg/2945356 to your computer and use it in GitHub Desktop.
# I'm proposing a few changes to the property system:
#
# 1. Instead of specifying the has_many and include, change it to a has_properties (like an acts_as_* plugin)
# Then we also configure the names of properties that need multiple instances, which gets it out of the controller.
# (I've already implemented this part locally and I think it looks a lot nicer)
#
# 2. On the first use of an object's properties, load all the object's properties into memory and
# operate on that cache, writing through to disk if need be. Editing employees, employers, and
# running payroll, all make use of multiple properties and this should be more efficient.
#
# 3. Instead of loading all the properties into instance vars and passing them into the view,
# provide two methods (one for single properties, one for multiple) that return either the saved
# property (from cache) or a new property, and get all that out of the controller. We can prime the cache
# from within the controller which would introduce no new overhead, but for metric purposes would not
# affect the time spent in the view
# The main driver for this is that the US stuff is going to introduce a dynamic list of properties depending
# on the state, and this eliminates a lot of controller/view code
module HasProperties
def property(name)
# Is the property cache empty?
# yes - get all the properties
# Fetch the property from cache
# hit - return it
# miss - self.properties.new(:key => name)
end
# other functions work the same, operating in write-through
# mode on the cache
end
class Employee < ActiveRecord::Base
has_properties :multiple => %w[salary, vacation, ...]
...
end
class EmployeeController < ApplicationController
end
_cra.html.haml:
= fields_for @employee.property('federal_claim') do |blah|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment