Archive for November 2009
I wrote this as a plugin….but it really has nothing to do with rails. I guess it could be packaged as a gem, but its so small that it probably doesn’t make sense. You ever create class variables or class instance variables and then create getters for them for use as statics?
class MyClass @items = [1,2,3] def self.items @items end end MyClass.items #[1,2,3]
class MyClass has_class_attr :items, :data => [1,2,3] end MyClass.items #[1,2,3]
.script/plugin install git://github.com/angelo0000/has_class_attr.git
Building on my previous post I created the has_duration_field plugin. As described, I wanted to represent a duration of time on a field in my model. Using the proxy_field plugin, I built the DurationField class and added it as the proxy for my columns tblk and tduty.
Before the has_duration_field plugin:
class Block < ActiveRecord::Base proxy_field [:tduty, :tblk], :as => DurationField end
I just implemented my DurationField class and threw it in my lib dir. As I did that I realized that really using proxy_field and the implementation of DurationField would make a neat little plugin.
With the plugin you can do this:
class Block < ActiveRecord::Base has_duration_field [:tduty, :tblk] end
The plugin just provides an implementation of the DurationField class for you and an easy way to make your column proxy to a DurationField.
./script/plugin install git://github.com/angelo0000/has_duration_field.git