Class: CC::Service
- Inherits:
-
Object
- Object
- CC::Service
- Defined in:
- lib/cc/service.rb,
lib/cc/service/response_check.rb,
lib/cc/presenters/pull_requests_presenter.rb
Direct Known Subclasses
Asana, Campfire, Flowdock, GitHubIssues, GitHubPullRequests, HipChat, Jira, Lighthouse, PivotalTracker, Slack, StashPullRequests
Defined Under Namespace
Modules: CoverageHelper, HTTP, Helper, IssueHelper, QualityHelper, VulnerabilityHelper Classes: Asana, Campfire, Config, Flowdock, Formatter, GitHubIssues, GitHubPullRequests, HTTPError, HipChat, Invocation, Jira, Lighthouse, PivotalTracker, PullRequestsPresenter, ResponseCheck, Slack, StashPullRequests
Constant Summary collapse
- Error =
Class.new(StandardError)
- ConfigurationError =
Class.new(Error)
- ALL_EVENTS =
%w[ coverage issue pull_request pull_request_coverage quality snapshot test unit vulnerability ].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.
82 83 84 85 86 87 88 89 |
# File 'lib/cc/service.rb', line 82 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.
61 62 63 |
# File 'lib/cc/service.rb', line 61 def description @description end |
.issue_tracker ⇒ Object
Returns the value of attribute issue_tracker.
62 63 64 |
# File 'lib/cc/service.rb', line 62 def issue_tracker @issue_tracker end |
.title ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/cc/service.rb', line 65 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.
31 32 33 |
# File 'lib/cc/service.rb', line 31 def config @config end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
31 32 33 |
# File 'lib/cc/service.rb', line 31 def event @event end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
31 32 33 |
# File 'lib/cc/service.rb', line 31 def payload @payload end |
Class Method Details
.by_slug(slug) ⇒ Object
55 56 57 |
# File 'lib/cc/service.rb', line 55 def self.by_slug(slug) services.detect { |s| s.slug == slug } end |
.inherited(svc) ⇒ Object
50 51 52 53 |
# File 'lib/cc/service.rb', line 50 def self.inherited(svc) Service.services << svc super end |
.load_services ⇒ Object
20 21 22 23 |
# File 'lib/cc/service.rb', line 20 def self.load_services path = File.("../services/**/*.rb", __FILE__) Dir[path].sort.each { |lib| require(lib) } end |
.services ⇒ Object
Tracks the defined services.
46 47 48 |
# File 'lib/cc/service.rb', line 46 def self.services @services ||= [] end |
.slug ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/cc/service.rb', line 73 def self.slug @slug ||= begin hook = name.dup hook.downcase! hook.sub! /.*:/, '' hook end end |
Instance Method Details
#receive ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cc/service.rb', line 91 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 |