class Tengine::Core::Event::Finder

Constants

ATTRIBUTE_NAMES

Public Class Methods

new(attrs = {}) click to toggle source
# File lib/tengine/core/event/finder.rb, line 25
def initialize(attrs = {})
  attrs = {
    :level_ids => default_level_ids
  }.update(attrs || {})
  attrs.each do |attr, v|
    send("#{attr}=", v) unless v.blank?
  end
end

Public Instance Methods

attributes() click to toggle source
# File lib/tengine/core/event/finder.rb, line 34
def attributes
  ATTRIBUTE_NAMES.inject({}){|d, name| d[name] = send(name); d}
end
default_level_ids() click to toggle source

デフォルトでは通知レベルがすべて選択された状態にする

# File lib/tengine/core/event/finder.rb, line 39
def default_level_ids
  result = []
  Tengine::Core::Event.level_entries.each do |entry|
    result << entry.id
  end
  return result
end
paginate(page = nil) click to toggle source
# File lib/tengine/core/event/finder.rb, line 47
def paginate(page = nil)
  result = scope(Tengine::Core::Event)
  if page || result.respond_to?(:page)
    result = result.page(page)
  end
  result
end
scope(criteria) click to toggle source
# File lib/tengine/core/event/finder.rb, line 55
def scope(criteria)
  result = criteria
  result = result.where(:event_type_name => str_or_regexp(event_type_name)) if event_type_name
  result = result.where(:key => key)  if key
  result = result.where(:source_name => str_or_regexp(source_name)) if source_name
  result = result.where(:occurred_at.gte => occurred_at_start) if occurred_at_start
  result = result.where(:occurred_at.lte =>  occurred_at_end) if occurred_at_end
  result = result.any_in(:level => level_ids) if level_ids
  result = result.where(:confirmed => confirmed) if confirmed
  result = result.where(:sender_name => str_or_regexp(sender_name)) if sender_name
  result = result.where(:properties => properties) if properties
  # ソート
  result = result.desc(:occurred_at)
  result
end

Private Instance Methods

str_or_regexp(val) click to toggle source
# File lib/tengine/core/event/finder.rb, line 72
def str_or_regexp(val)
  if val =~ %r{\A\/(.+)\/\Z}
    /#{$1}/
  else
    /\A#{Regexp.escape(val)}/
  end
end