Class: MongodbLogger::ServerModel::Filter

Inherits:
Base
  • Object
show all
Defined in:
lib/mongodb_logger/server/model/filter.rb

Constant Summary

DEFAULT_LIMIT =
100
FIXED_PARAMS_ON_FORM =
['action', 'controller', 'ip', 'application_name', 'is_exception', 'limit']
FORM_NAME =

dynamic filters

"filter"

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base

#create_variable, #set_params_to_methods

Constructor Details

- (Filter) initialize(params)



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mongodb_logger/server/model/filter.rb', line 14

def initialize(params)
  FIXED_PARAMS_ON_FORM.each do |key|
    create_variable(key, nil)
  end
  @params = params
  set_params_to_methods
  # limits
  self.limit = DEFAULT_LIMIT.to_s if self.limit.nil?
  # dynamic filters
  create_dynamic_filters
  # build mongo conditions
  build_mongo_conditions
end

Instance Attribute Details

- (Object) mongo_conditions (readonly)

Returns the value of attribute mongo_conditions



9
10
11
# File 'lib/mongodb_logger/server/model/filter.rb', line 9

def mongo_conditions
  @mongo_conditions
end

- (Object) more_filters

Returns the value of attribute more_filters



12
13
14
# File 'lib/mongodb_logger/server/model/filter.rb', line 12

def more_filters
  @more_filters
end

- (Object) params (readonly)

Returns the value of attribute params



9
10
11
# File 'lib/mongodb_logger/server/model/filter.rb', line 9

def params
  @params
end

Instance Method Details

- (Object) build_mongo_conditions



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mongodb_logger/server/model/filter.rb', line 35

def build_mongo_conditions
  @mongo_conditions = Hash.new
  FIXED_PARAMS_ON_FORM.each do |param_key|
    value = self.send param_key
    mkey_val = case param_key
    when 'is_exception'
      (value ? true : nil)
    when 'limit'
      nil # skip
    else
      value
    end
    @mongo_conditions[param_key.to_s] = mkey_val if !mkey_val.nil? && !mkey_val.blank?
  end

  self.more_filters.each do |m_filter|
    unless m_filter.mongo_conditions.blank?
      cond = m_filter.mongo_conditions
      if @mongo_conditions[m_filter.key] && @mongo_conditions[m_filter.key].is_a?(Hash)
        @mongo_conditions[m_filter.key].merge!(cond[m_filter.key])
      else
       @mongo_conditions.merge!(m_filter.mongo_conditions)
      end
    end
  end unless self.more_filters.blank?
end

- (Object) create_dynamic_filters



28
29
30
31
32
33
# File 'lib/mongodb_logger/server/model/filter.rb', line 28

def create_dynamic_filters
  self.more_filters = []
  @params[AdditionalFilter::FORM_NAME].each do |filter|
    self.more_filters << AdditionalFilter.new(filter, self)
  end if !@params.blank? && @params[AdditionalFilter::FORM_NAME] && !@params[AdditionalFilter::FORM_NAME].blank?
end

- (Object) form_name



70
71
72
# File 'lib/mongodb_logger/server/model/filter.rb', line 70

def form_name
  FORM_NAME
end

- (Object) get_mongo_conditions



62
63
64
# File 'lib/mongodb_logger/server/model/filter.rb', line 62

def get_mongo_conditions
  @mongo_conditions
end

- (Object) get_mongo_limit



66
67
68
# File 'lib/mongodb_logger/server/model/filter.rb', line 66

def get_mongo_limit
  self.limit.to_i
end