Class: MongodbLogger::ServerModel::Filter
- Defined in:
- lib/mongodb_logger/server/model/filter.rb
Constant Summary collapse
- DEFAULT_LIMIT =
100
- FIXED_PARAMS_ON_FORM =
['action', 'controller', 'ip', 'application_name', 'is_exception', 'limit']
- FORM_NAME =
dynamic filters
"filter"
Instance Attribute Summary collapse
-
#mongo_conditions ⇒ Object
readonly
Returns the value of attribute mongo_conditions.
-
#more_filters ⇒ Object
Returns the value of attribute more_filters.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #build_mongo_conditions ⇒ Object
- #create_dynamic_filters ⇒ Object
- #form_name ⇒ Object
- #get_mongo_conditions ⇒ Object
- #get_mongo_limit ⇒ Object
-
#initialize(params) ⇒ Filter
constructor
A new instance of Filter.
Methods inherited from Base
#create_variable, #set_params_to_methods
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
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
#mongo_conditions ⇒ Object (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 |
#more_filters ⇒ Object
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 |
#params ⇒ Object (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
#build_mongo_conditions ⇒ Object
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 |
#create_dynamic_filters ⇒ Object
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 |
#form_name ⇒ Object
70 71 72 |
# File 'lib/mongodb_logger/server/model/filter.rb', line 70 def form_name FORM_NAME end |
#get_mongo_conditions ⇒ Object
62 63 64 |
# File 'lib/mongodb_logger/server/model/filter.rb', line 62 def get_mongo_conditions @mongo_conditions end |
#get_mongo_limit ⇒ Object
66 67 68 |
# File 'lib/mongodb_logger/server/model/filter.rb', line 66 def get_mongo_limit self.limit.to_i end |