Class: CC::Service
- Inherits:
-
Object
- Object
- CC::Service
- Defined in:
- lib/cc/service.rb,
lib/cc/service/safe_webhook.rb,
lib/cc/service/response_check.rb,
lib/cc/presenters/pull_requests_presenter.rb
Direct Known Subclasses
PullRequests, Asana, Campfire, Flowdock, GitHubIssues, HipChat, Jira, Lighthouse, PivotalTracker, Slack, StashPullRequests
Defined Under Namespace
Modules: CoverageHelper, HTTP, Helper, IssueHelper, QualityHelper, VulnerabilityHelper Classes: Asana, Campfire, Config, Flowdock, Formatter, GitHubIssues, GitHubPullRequests, GitlabMergeRequests, HTTPError, HipChat, Invocation, Jira, Lighthouse, PivotalTracker, PullRequestsPresenter, ResponseCheck, SafeWebhook, Slack, StashPullRequests
Constant Summary collapse
- Error =
Class.new(StandardError)
- ConfigurationError =
Class.new(Error)
- ALL_EVENTS =
%w[ coverage issue pull_request pull_request_coverage pull_request_diff_coverage pull_request_total_coverage quality snapshot test unit vulnerability ].freeze
- ABSTRACT_SLUGS =
%w[ pullrequests ].freeze
Constants included from Helper
Helper::GREEN_HEX, Helper::RED_HEX
Constants included from HTTP
Class Attribute Summary collapse
-
.description ⇒ Object
Returns the value of attribute description.
-
.issue_tracker ⇒ Object
Returns the value of attribute issue_tracker.
- .title ⇒ Object
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Class Method Summary collapse
- .by_slug(slug) ⇒ Object
- .inherited(svc) ⇒ Object
- .load_services ⇒ Object
-
.services ⇒ Object
Tracks the defined services.
- .slug ⇒ Object
Instance Method Summary collapse
-
#initialize(config, payload) ⇒ Service
constructor
A new instance of Service.
- #receive ⇒ Object
Methods included from Helper
#changed, #color, #compare_url, #details_url, #emoji, #hex_color, #improved?, #repo_name
Methods included from HTTP
#ca_file, #formatted_post_response, #http, #http_method, #raw_get, #raw_post, #service_get, #service_post, #service_post_with_redirects
Constructor Details
#initialize(config, payload) ⇒ Service
Returns a new instance of Service.
91 92 93 94 95 96 97 98 |
# File 'lib/cc/service.rb', line 91 def initialize(config, payload) @payload = payload.stringify_keys @config = create_config(config) @event = @payload["name"].to_s load_helper validate_event end |
Class Attribute Details
.description ⇒ Object
Returns the value of attribute description.
70 71 72 |
# File 'lib/cc/service.rb', line 70 def description @description end |
.issue_tracker ⇒ Object
Returns the value of attribute issue_tracker.
71 72 73 |
# File 'lib/cc/service.rb', line 71 def issue_tracker @issue_tracker end |
.title ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/cc/service.rb', line 74 def self.title @title ||= begin hook = name.dup hook.sub!(/.*:/, "") hook end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
32 33 34 |
# File 'lib/cc/service.rb', line 32 def config @config end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
32 33 34 |
# File 'lib/cc/service.rb', line 32 def event @event end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
32 33 34 |
# File 'lib/cc/service.rb', line 32 def payload @payload end |
Class Method Details
.by_slug(slug) ⇒ Object
64 65 66 |
# File 'lib/cc/service.rb', line 64 def self.by_slug(slug) services.detect { |s| s.slug == slug } end |
.inherited(svc) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/cc/service.rb', line 57 def self.inherited(svc) unless ABSTRACT_SLUGS.include?(svc.slug) Service.services << svc end super end |
.load_services ⇒ Object
21 22 23 24 |
# File 'lib/cc/service.rb', line 21 def self.load_services path = File.("../services/**/*.rb", __FILE__) Dir[path].sort.each { |lib| require(lib) } end |
.services ⇒ Object
Tracks the defined services.
53 54 55 |
# File 'lib/cc/service.rb', line 53 def self.services @services ||= [] end |
.slug ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/cc/service.rb', line 82 def self.slug @slug ||= begin hook = name.dup hook.downcase! hook.sub!(/.*:/, "") hook end end |
Instance Method Details
#receive ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/cc/service.rb', line 100 def receive methods = [:receive_event, :"receive_#{event}"] methods.each do |method| if respond_to?(method) return public_send(method) end end { ok: false, ignored: true, message: "No service handler found" } end |