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
- #symbolized_data ⇒ Object
-
#to_h ⇒ Hash
Returns a hash representative.
Class Method Details
.count(filter) ⇒ Integer
Count alerts
58 59 60 61 |
# File 'lib/mihari/models/rule.rb', line 58 def count(filter) relation = build_relation(filter) relation.distinct("rules.id").count end |
.search(filter) ⇒ Array<Rule>
Search rules
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mihari/models/rule.rb', line 35 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 |
#to_h ⇒ Hash
Returns a hash representative
18 19 20 21 22 23 24 25 |
# File 'lib/mihari/models/rule.rb', line 18 def to_h { id: id, yaml: yaml || data.to_yaml, created_at: created_at, updated_at: updated_at } end |