Class: Mihari::Rule
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Mihari::Rule
- Defined in:
- lib/mihari/models/rule.rb
Class Method Summary collapse
-
.count(filter) ⇒ Integer
Count alerts.
-
.search(filter) ⇒ Array<Rule>
Search rules.
Instance Method Summary collapse
Class Method Details
.count(filter) ⇒ Integer
Count alerts
52 53 54 55 |
# File 'lib/mihari/models/rule.rb', line 52 def count(filter) relation = build_relation(filter) relation.distinct("rules.id").count end |
.search(filter) ⇒ Array<Rule>
Search rules
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mihari/models/rule.rb', line 29 def search(filter) limit = filter.limit.to_i raise ArgumentError, "limit should be bigger than zero" unless limit.positive? page = filter.page.to_i raise ArgumentError, "page should be bigger than zero" unless page.positive? offset = (page - 1) * limit relation = build_relation(filter.without_pagination) # TODO: improve queires rule_ids = relation.limit(limit).offset(offset).order(created_at: :desc).pluck(:id).uniq where(id: [rule_ids]).order(created_at: :desc) end |
Instance Method Details
#symbolized_data ⇒ Object
9 10 11 |
# File 'lib/mihari/models/rule.rb', line 9 def symbolized_data @symbolized_data ||= data.deep_symbolize_keys end |
#tags ⇒ Object
17 18 19 |
# File 'lib/mihari/models/rule.rb', line 17 def (data["tags"] || []).map { |tag| { name: tag } } end |
#yaml ⇒ Object
13 14 15 |
# File 'lib/mihari/models/rule.rb', line 13 def yaml data.to_yaml end |