Module: Houston::Props::ClassMethods
- Defined in:
- app/concerns/houston/props.rb
Instance Method Summary collapse
Instance Method Details
#find_by_prop(prop_name, value) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/concerns/houston/props.rb', line 24 def find_by_prop(prop_name, value) result = with_prop(prop_name, value).limit(1).first if !result && block_given? result = yield value if result result.update_prop! prop_name, value else Rails.logger.info "\e[34mUnable to identify a #{name} where \e[1m#{prop_name}\e[0;34m=\e[1m#{value}\e[0m" end end result end |
#with_prop(prop_name, *args) ⇒ Object
18 19 20 21 22 |
# File 'app/concerns/houston/props.rb', line 18 def with_prop(prop_name, *args) Houston::Props.valid_prop_name!(prop_name) return where(["props ? :key", { key: prop_name }]) if args.empty? where(["props->>? = ?", prop_name, args.first.to_s]) end |