Class: SkullIsland::Resources::UpstreamTarget
- Inherits:
-
SkullIsland::Resource
- Object
- SkullIsland::Resource
- SkullIsland::Resources::UpstreamTarget
- Includes:
- Helpers::Meta
- Defined in:
- lib/skull_island/resources/upstream_target.rb
Overview
The Upstream Target resource class
Instance Attribute Summary
Attributes inherited from SkullIsland::Resource
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity.
-
.batch_import(data, verbose: false, test: false, project: nil, time: nil) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
- .get(id, options = {}) ⇒ Object
Instance Method Summary collapse
-
#created_at ⇒ Object
The created_at property.
- #export(options = {}) ⇒ Object
-
#find_by_digest ⇒ Object
Tests for an existing version of this resource based on its properties rather than its ‘id`.
- #modified_existing? ⇒ Boolean
- #relative_uri ⇒ Object
- #save_uri ⇒ Object
-
#tags ⇒ Object
The tags property.
-
#target ⇒ Object
The target property.
-
#upstream ⇒ Object
The upstream property.
-
#weight ⇒ Object
The weight property.
Methods included from Helpers::Meta
#add_meta, #import_time, #import_time=, #metatags, #postprocess_tags, #preprocess_tags, #project, #project=, #raw_tags, #remove_meta, #supports_meta?
Methods inherited from SkullIsland::Resource
cleanup_except, find, from_hash, gen_getter_method, gen_property_methods, gen_setter_method, immutable, #initialize, property, 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, #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, #recursive_erubi, #reload, #required_properties, #save, #supports_meta?, #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
.all(options = {}) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity
45 46 47 48 49 |
# File 'lib/skull_island/resources/upstream_target.rb', line 45 def self.all( = {}) api_client = [:api_client] || APIClient.instance Upstream.all(api_client: api_client).map(&:targets).reduce(&:merge) end |
.batch_import(data, verbose: false, test: false, project: nil, time: nil) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/skull_island/resources/upstream_target.rb', line 23 def self.batch_import(data, verbose: false, test: false, project: nil, time: nil) raise(Exceptions::InvalidArguments) unless data.is_a?(Array) known_ids = [] data.each_with_index do |resource_data, index| resource = new resource.delayed_set(:target, resource_data) resource.delayed_set(:upstream, resource_data) resource.weight = resource_data['weight'] if resource_data['weight'] resource. = resource_data['tags'] if resource_data['tags'] resource.project = project if project resource.import_time = (time || Time.now.utc.to_i) if project resource.import_update_or_skip(index: index, verbose: verbose, test: test) known_ids << resource.id end cleanup_except(project, known_ids) if project end |
.get(id, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/skull_island/resources/upstream_target.rb', line 51 def self.get(id, = {}) if [:upstream]&.is_a?(Upstream) [:upstream].target(id) elsif [:upstream] upstream_opts = .merge(lazy: true) Upstream.get([:upstream], upstream_opts).target(id) end end |
Instance Method Details
#created_at ⇒ Object
The created_at property
18 |
# File 'lib/skull_island/resources/upstream_target.rb', line 18 property :created_at, read_only: true, postprocess: true |
#export(options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/skull_island/resources/upstream_target.rb', line 81 def export( = {}) hash = { 'target' => target, 'weight' => weight } hash['upstream'] = "<%= lookup :upstream, '#{upstream.name}' %>" if upstream hash['tags'] = unless .empty? [*[: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 |
#find_by_digest ⇒ Object
Tests for an existing version of this resource based on its properties rather than its ‘id`
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/skull_island/resources/upstream_target.rb', line 61 def find_by_digest result = self.class.where(:digest, digest) # matching digest means the equivalent resource if result.size == 1 @entity = result.first.entity @lazy = false @tainted = false true else false end end |
#modified_existing? ⇒ Boolean
94 95 96 |
# File 'lib/skull_island/resources/upstream_target.rb', line 94 def modified_existing? false # Upstream Targets can not be PATCHed, so can not be modified end |
#relative_uri ⇒ Object
73 74 75 |
# File 'lib/skull_island/resources/upstream_target.rb', line 73 def relative_uri upstream ? "#{upstream.relative_uri}/targets/#{id}" : nil end |
#save_uri ⇒ Object
77 78 79 |
# File 'lib/skull_island/resources/upstream_target.rb', line 77 def save_uri upstream ? "#{upstream.relative_uri}/targets" : nil end |
#tags ⇒ Object
The tags property
19 |
# File 'lib/skull_island/resources/upstream_target.rb', line 19 property :tags, validate: true, preprocess: true, postprocess: true |
#target ⇒ Object
The target property
12 |
# File 'lib/skull_island/resources/upstream_target.rb', line 12 property :target, required: true, validate: true, preprocess: true |
#upstream ⇒ Object
The upstream property
13 14 15 16 |
# File 'lib/skull_island/resources/upstream_target.rb', line 13 property( :upstream, required: true, validate: true, preprocess: true, postprocess: true ) |
#weight ⇒ Object
The weight property
17 |
# File 'lib/skull_island/resources/upstream_target.rb', line 17 property :weight, validate: true |