Last active
December 15, 2015 20:59
-
-
Save hotgazpacho/5322343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HStoreProperties | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def boolean_h_store_fields_for(property_names) | |
property_names.each do |key| | |
attr_accessible key | |
scope "has_#{key}", lambda { |value| where('properties @> (? => ?)', key, value) } | |
send :define_method, key do | |
properties && properties[key].to_bool | |
end | |
send :define_method, "#{key}?".to_sym do | |
send key | |
end | |
send :define_method, "#{key}=" do |value| | |
self.properties = (properties || {}).merge(key => value) | |
end | |
end | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pump < Component | |
include HStoreProperties | |
boolean_h_store_fields_for %w[variable_speed skid_mounted speed_lock flow_lock press_lock] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got it fixed now :)