Sha256: e59e6d7cc5472a0eb6f8800903d97e1a395a2569005018bd88e44821c1ede4c4
Contents?: true
Size: 1.02 KB
Versions: 15
Compression:
Stored size: 1.02 KB
Contents
module JeraPush class DeviceFilter include ActiveModel::Model attr_accessor :platform, :value, :field, :message_id, :resource_name def platform @platform ||= [] end def search @scope = resource_name.present? ? JeraPush::Device.with_joins(resource_name) : @scope = JeraPush::Device.all if message_id @scope = @scope.joins(:messages).where('jera_push_messages.id = ?', message_id) end if platform.any? @scope = @scope.where('jera_push_devices.platform in (?)', platform) end if field.present? && value.present? @scope = search_with_value_field(@scope) end @scope end private def search_with_value_field(scope) if field.to_sym == :token return scope.where('jera_push_devices.token like ?', "%#{value}%") elsif JeraPush.resource_attributes.include?(field.to_sym) return scope.where("#{resource_name.constantize.table_name}.#{field} like ?", "%#{value}%") end return scope end end end
Version data entries
15 entries across 15 versions & 1 rubygems