Module: Filters::Resource::ClassMethods
- Defined in:
- lib/dm-filters.rb
Instance Method Summary collapse
- #filtered_properties ⇒ Object
-
#property(name, type, options = {}) ⇒ Object
Override DataMapper’s
property
class method to accept as an optionfilter
.
Instance Method Details
#filtered_properties ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/dm-filters.rb', line 127 def filtered_properties begin # This is to work with STI models. It's not a very good solution. @filtered_properties || self.superclass.filtered_properties rescue nil end end |
#property(name, type, options = {}) ⇒ Object
Override DataMapper’s property
class method to accept as an option filter
. filter
Hash with the following pairs:
-
:to
- Name of property to filter to; this should not be explicitly declared as a property. -
:with
- Either 1) Name of the property (as a symbol) that designates filter (does not need to be explicitly declared as a property) or 2) A semi-colon delimited String represented filters to use (or an Array of strings). -
:default
- A semi-colon delimited String represented filters to use (or an Array of strings) if the filter column is blank.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/dm-filters.rb', line 110 def property(name, type, = {}) if filter = .delete(:filter) @filtered_properties ||= [] @filtered_properties << filter.merge({:name => name}) unless self.properties.named?(filter[:to]) self.property(filter[:to], String) end if filter[:with].kind_of?(Symbol) unless self.properties.named?(filter[:with]) self.property(filter[:with], String) end end end super(name, type, ) end |