Class: SkullIsland::Resources::UpstreamTarget
- Inherits:
-
SkullIsland::Resource
- Object
- SkullIsland::Resource
- SkullIsland::Resources::UpstreamTarget
- 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
- .batch_import(data, verbose: false, test: false) ⇒ Object
- .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 inherited from SkullIsland::Resource
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, #reload, #required_properties, #save, #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
32 33 34 35 36 |
# File 'lib/skull_island/resources/upstream_target.rb', line 32 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) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/skull_island/resources/upstream_target.rb', line 19 def self.batch_import(data, verbose: false, test: false) raise(Exceptions::InvalidArguments) unless data.is_a?(Array) data.each_with_index do |resource_data, index| resource = new resource.target = resource_data['target'] resource.delayed_set(:upstream, resource_data, 'upstream') resource.weight = resource_data['weight'] if resource_data['weight'] resource. = resource_data['tags'] if resource_data['tags'] resource.import_update_or_skip(index: index, verbose: verbose, test: test) end end |
.get(id, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/skull_island/resources/upstream_target.rb', line 38 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
16 |
# File 'lib/skull_island/resources/upstream_target.rb', line 16 property :created_at, read_only: true, postprocess: true |
#export(options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/skull_island/resources/upstream_target.rb', line 68 def export( = {}) hash = { 'target' => target, 'weight' => weight } hash['upstream'] = "<%= lookup :upstream, '#{upstream.name}' %>" if upstream 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 |
#find_by_digest ⇒ Object
Tests for an existing version of this resource based on its properties rather than its ‘id`
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/skull_island/resources/upstream_target.rb', line 48 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
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/skull_island/resources/upstream_target.rb', line 81 def modified_existing? return false unless new? # Find routes of the same name same_target_and_upstream = self.class.where(:target, target).and(:upstream, upstream) existing = same_target_and_upstream.size == 1 ? same_target_and_upstream.first : nil if existing @entity['id'] = existing.id save else false end end |
#relative_uri ⇒ Object
60 61 62 |
# File 'lib/skull_island/resources/upstream_target.rb', line 60 def relative_uri upstream ? "#{upstream.relative_uri}/targets/#{id}" : nil end |
#save_uri ⇒ Object
64 65 66 |
# File 'lib/skull_island/resources/upstream_target.rb', line 64 def save_uri upstream ? "#{upstream.relative_uri}/targets" : nil end |
#tags ⇒ Object
The tags property
17 |
# File 'lib/skull_island/resources/upstream_target.rb', line 17 property :tags, validate: true |
#target ⇒ Object
The target property
10 |
# File 'lib/skull_island/resources/upstream_target.rb', line 10 property :target, required: true, validate: true, preprocess: true |
#upstream ⇒ Object
The upstream property
11 12 13 14 |
# File 'lib/skull_island/resources/upstream_target.rb', line 11 property( :upstream, required: true, validate: true, preprocess: true, postprocess: true ) |
#weight ⇒ Object
The weight property
15 |
# File 'lib/skull_island/resources/upstream_target.rb', line 15 property :weight, validate: true |