Class: MongodbLogger::ServerModel::Filter
- Inherits:
-
Object
- Object
- MongodbLogger::ServerModel::Filter
- 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)
-
- (Object) mongo_conditions
readonly
Returns the value of attribute mongo_conditions.
-
- (Object) more_filters
Returns the value of attribute more_filters.
-
- (Object) params
readonly
Returns the value of attribute params.
Instance Method Summary (collapse)
- - (Object) build_mongo_conditions
- - (Object) create_dynamic_filters
- - (Object) create_variable(k, v)
- - (Object) form_name
- - (Object) get_mongo_conditions
- - (Object) get_mongo_limit
-
- (Filter) initialize(params)
constructor
A new instance of Filter.
Constructor Details
- (Filter) initialize(params)
A new instance of Filter
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 @params.each do |k,v| self.send("#{k}=", v) if self.respond_to?(k) && v && !v.blank? end unless @params.blank? # 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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mongodb_logger/server/model/filter.rb', line 43 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
36 37 38 39 40 41 |
# File 'lib/mongodb_logger/server/model/filter.rb', line 36 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) create_variable(k, v)
30 31 32 33 34 |
# File 'lib/mongodb_logger/server/model/filter.rb', line 30 def create_variable(k, v) self.instance_variable_set("@#{k}", v) ## create instance variable self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## method to return instance variable self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## method to set instance variable end |
- (Object) form_name
78 79 80 |
# File 'lib/mongodb_logger/server/model/filter.rb', line 78 def form_name FORM_NAME end |
- (Object) get_mongo_conditions
70 71 72 |
# File 'lib/mongodb_logger/server/model/filter.rb', line 70 def get_mongo_conditions @mongo_conditions end |
- (Object) get_mongo_limit
74 75 76 |
# File 'lib/mongodb_logger/server/model/filter.rb', line 74 def get_mongo_limit self.limit.to_i end |