Class: SkullIsland::Resources::Service
- Inherits:
-
SkullIsland::Resource
- Object
- SkullIsland::Resource
- SkullIsland::Resources::Service
- Defined in:
- lib/skull_island/resources/service.rb
Overview
The Service resource class
Instance Attribute Summary
Attributes inherited from SkullIsland::Resource
Class Method Summary collapse
-
.batch_import(data, verbose: false, test: false) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/AbcSize.
Instance Method Summary collapse
-
#add_route!(details) ⇒ Object
Convenience method to add routes.
-
#connect_timeout ⇒ Object
The connect_timeout property.
-
#created_at ⇒ Object
The created_at property.
- #export(options = {}) ⇒ Object
-
#host ⇒ Object
The host property.
- #modified_existing? ⇒ Boolean
-
#name ⇒ Object
The name property.
-
#path ⇒ Object
The path property.
-
#plugins ⇒ Object
Provides a collection of related Plugin instances.
-
#port ⇒ Object
The port property.
-
#protocol ⇒ Object
The protocol property.
-
#read_timeout ⇒ Object
The read_timeout property.
-
#retries ⇒ Object
The retries property.
-
#routes ⇒ Object
Provides a collection of related Route instances.
-
#tags ⇒ Object
The tags property.
-
#updated_at ⇒ Object
The updated_at property.
- #url ⇒ Object
- #url=(uri_or_string) ⇒ Object
-
#write_timeout ⇒ Object
The write_timeout property.
Methods inherited from SkullIsland::Resource
all, find, from_hash, gen_getter_method, gen_property_methods, gen_setter_method, get, immutable, #initialize, property, relative_uri, #relative_uri, where
Methods included from Helpers::ResourceClass
#determine_getter_names, #determine_setter_names, #human, #i18n_key, #immutable?, #param_key, #properties, #route_key
Methods included from Helpers::Resource
#<=>, #datetime_from_params, #delayed_set, #destroy, #digest, #digest_properties, #find_by_digest, #fresh?, #host_regex, #id, #id_property, #immutable?, #import_update_or_skip, #lookup, #model_name, #new?, #persisted?, #postprocess_created_at, #postprocess_updated_at, #properties, #prune_for_save, #reload, #required_properties, #save, #save_uri, #tainted?, #to_param, #to_s, #update
Methods included from Validations::Resource
#validate_id, #validate_mutability, #validate_required_properties, #validate_tags
Constructor Details
This class inherits a constructor from SkullIsland::Resource
Class Method Details
.batch_import(data, verbose: false, test: false) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/AbcSize
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/skull_island/resources/service.rb', line 26 def self.batch_import(data, verbose: false, test: false) raise(Exceptions::InvalidArguments) unless data.is_a?(Array) data.each_with_index do |rdata, index| resource = new resource.name = rdata['name'] resource.retries = rdata['retries'] if rdata['retries'] resource.protocol = rdata['protocol'] resource.host = rdata['host'] resource.port = rdata['port'] resource.path = rdata['path'] if rdata['path'] resource.connect_timeout = rdata['connect_timeout'] if rdata['connect_timeout'] resource.write_timeout = rdata['write_timeout'] if rdata['write_timeout'] resource.read_timeout = rdata['read_timeout'] if rdata['read_timeout'] resource. = rdata['tags'] if rdata['tags'] resource.import_update_or_skip(index: index, verbose: verbose, test: test) Route.batch_import( (rdata['routes'] || []).map { |r| r.merge('service' => { 'id' => resource.id }) }, verbose: verbose, test: test ) end end |
Instance Method Details
#add_route!(details) ⇒ Object
Convenience method to add routes
55 56 57 58 59 60 |
# File 'lib/skull_island/resources/service.rb', line 55 def add_route!(details) r = details.is_a?(Route) ? details : Route.from_hash(details, api_client: api_client) r.service = self r.save end |
#connect_timeout ⇒ Object
The connect_timeout property
16 |
# File 'lib/skull_island/resources/service.rb', line 16 property :connect_timeout, validate: true |
#created_at ⇒ Object
The created_at property
19 |
# File 'lib/skull_island/resources/service.rb', line 19 property :created_at, read_only: true, postprocess: true |
#export(options = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/skull_island/resources/service.rb', line 72 def export( = {}) hash = { 'name' => name, 'retries' => retries, 'protocol' => protocol, 'host' => host, 'port' => port, 'path' => path, 'connect_timeout' => connect_timeout, 'write_timeout' => write_timeout, 'read_timeout' => read_timeout } hash['routes'] = routes.collect { |route| route.export(exclude: 'service') } hash['tags'] = if [*[:exclude]].each do |exclude| hash.delete(exclude.to_s) end [*[:include]].each do |inc| hash[inc.to_s] = send(inc.to_sym) end hash.reject { |_, value| value.nil? } end |
#host ⇒ Object
The host property
13 |
# File 'lib/skull_island/resources/service.rb', line 13 property :host, validate: true, required: true |
#modified_existing? ⇒ Boolean
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/skull_island/resources/service.rb', line 95 def modified_existing? return false unless new? # Find routes of the same name same_name = self.class.where(:name, name) existing = same_name.size == 1 ? same_name.first : nil if existing @entity['id'] = existing.id save else false end end |
#name ⇒ Object
The name property
10 |
# File 'lib/skull_island/resources/service.rb', line 10 property :name |
#path ⇒ Object
The path property
15 |
# File 'lib/skull_island/resources/service.rb', line 15 property :path |
#plugins ⇒ Object
Provides a collection of related Plugin instances
68 69 70 |
# File 'lib/skull_island/resources/service.rb', line 68 def plugins Plugin.where(:service, self, api_client: api_client) end |
#port ⇒ Object
The port property
14 |
# File 'lib/skull_island/resources/service.rb', line 14 property :port, validate: true, required: true |
#protocol ⇒ Object
The protocol property
12 |
# File 'lib/skull_island/resources/service.rb', line 12 property :protocol, validate: true, required: true |
#read_timeout ⇒ Object
The read_timeout property
18 |
# File 'lib/skull_island/resources/service.rb', line 18 property :read_timeout, validate: true |
#retries ⇒ Object
The retries property
11 |
# File 'lib/skull_island/resources/service.rb', line 11 property :retries |
#routes ⇒ Object
Provides a collection of related Route instances
63 64 65 |
# File 'lib/skull_island/resources/service.rb', line 63 def routes Route.where(:service, self, api_client: api_client) end |
#tags ⇒ Object
The tags property
21 |
# File 'lib/skull_island/resources/service.rb', line 21 property :tags, validate: true |
#updated_at ⇒ Object
The updated_at property
20 |
# File 'lib/skull_island/resources/service.rb', line 20 property :updated_at, read_only: true, postprocess: true |
#url ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/skull_island/resources/service.rb', line 118 def url u = URI('') u.scheme = protocol u.host = host u.port = port unless [80, 443].include? port u.to_s end |
#url=(uri_or_string) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/skull_island/resources/service.rb', line 111 def url=(uri_or_string) uri_data = URI(uri_or_string) self.protocol = uri_data.scheme self.host = uri_data.host self.port = uri_data.port end |
#write_timeout ⇒ Object
The write_timeout property
17 |
# File 'lib/skull_island/resources/service.rb', line 17 property :write_timeout, validate: true |