Class: Tokite::Rule

Inherits:
ApplicationRecord show all
Defined in:
app/models/tokite/rule.rb

Constant Summary collapse

INVALID_CHANNEL_CHARS =
[" ", ","]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#search_queryObject (readonly)

Returns the value of attribute search_query.



3
4
5
# File 'app/models/tokite/rule.rb', line 3

def search_query
  @search_query
end

Class Method Details

.matched_rules(event) ⇒ Object

TODO: Performance



17
18
19
20
21
# File 'app/models/tokite/rule.rb', line 17

def self.matched_rules(event)
  Rule.all.to_a.select do |rule|
    rule.match?(event)
  end
end

Instance Method Details

#match?(event) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/tokite/rule.rb', line 27

def match?(event)
  search_query.match?(event.fields)
end


39
40
41
# File 'app/models/tokite/rule.rb', line 39

def rule_name_link
  "<#{Tokite::Engine.routes.url_helpers.edit_rule_url(self)}|#{name}>"
end

#slack_attachment_fallbackObject



31
32
33
# File 'app/models/tokite/rule.rb', line 31

def slack_attachment_fallback
  "#{name} by #{user.name}"
end

#slack_attachment_textObject



35
36
37
# File 'app/models/tokite/rule.rb', line 35

def slack_attachment_text
  "#{rule_name_link} (#{user_link}) "
end


43
44
45
# File 'app/models/tokite/rule.rb', line 43

def user_link
  "<#{Tokite::Engine.routes.url_helpers.user_url(user)}|#{user.name}>"
end