class JeraPush::DeviceFilter
Attributes
field[RW]
message_id[RW]
platform[RW]
resource_name[RW]
value[RW]
Public Instance Methods
search()
click to toggle source
# File lib/jera_push/models/device_filter.rb, line 11 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 Instance Methods
search_with_value_field(scope)
click to toggle source
# File lib/jera_push/models/device_filter.rb, line 27 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