Class: SkullIsland::Resources::Route
- Inherits:
-
SkullIsland::Resource
- Object
- SkullIsland::Resource
- SkullIsland::Resources::Route
- Includes:
- Helpers::Meta
- Defined in:
- lib/skull_island/resources/route.rb
Overview
The Route resource class
Instance Attribute Summary
Attributes inherited from SkullIsland::Resource
Class Method Summary collapse
-
.batch_import(data, verbose: false, test: false, project: nil, time: nil, cleanup: true) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/AbcSize rubocop:disable Layout/LineLength.
Instance Method Summary collapse
-
#created_at ⇒ Object
The created_at property.
-
#destinations ⇒ Object
The destinations property.
-
#export(options = {}) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/AbcSize.
-
#headers ⇒ Object
The headers property.
-
#hosts ⇒ Object
The hosts property.
-
#https_redirect_status_code ⇒ Object
The https_redirect_status_code property.
-
#methods ⇒ Object
The methods property.
-
#modified_existing? ⇒ Boolean
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity rubocop:enable Metrics/AbcSize.
-
#name ⇒ Object
The name property.
-
#path_handling ⇒ Object
The path_handling property.
-
#paths ⇒ Object
The paths property.
-
#plugins ⇒ Object
Provides a collection of related Plugin instances.
-
#preserve_host ⇒ Object
The preserve_host property.
-
#protocols ⇒ Object
The protocols property.
-
#regex_priority ⇒ Object
The regex_priority property.
-
#service ⇒ Object
The service property.
-
#snis ⇒ Object
The snis property.
-
#sources ⇒ Object
The sources property.
-
#strip_path ⇒ Object
The strip_path property.
-
#tags ⇒ Object
The tags property.
-
#updated_at ⇒ Object
The updated_at 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
all, cleanup_except, 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, #recursive_erubi, #reload, #required_properties, #save, #save_uri, #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
.batch_import(data, verbose: false, test: false, project: nil, time: nil, cleanup: true) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/AbcSize rubocop:disable Layout/LineLength
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/skull_island/resources/route.rb', line 35 def self.batch_import(data, verbose: false, test: false, project: nil, time: nil, cleanup: true) raise(Exceptions::InvalidArguments) unless data.is_a?(Array) known_ids = [] data.each_with_index do |rdata, index| resource = new resource.name = rdata['name'] resource.methods = rdata['methods'] if rdata['methods'] resource.paths = rdata['paths'] if rdata['paths'] resource.protocols = rdata['protocols'] if rdata['protocols'] resource.delayed_set(:hosts, rdata) if rdata['hosts'] resource.delayed_set(:headers, rdata) if rdata['headers'] if rdata['https_redirect_status_code'] resource.https_redirect_status_code = rdata['https_redirect_status_code'] end resource.regex_priority = rdata['regex_priority'] if rdata['regex_priority'] resource.strip_path = rdata['strip_path'] unless rdata['strip_path'].nil? resource.preserve_host = rdata['preserve_host'] unless rdata['preserve_host'].nil? resource.delayed_set(:snis, rdata) if rdata['snis'] resource. = rdata['tags'] if rdata['tags'] resource.project = project if project resource.import_time = (time || Time.now.utc.to_i) if project resource.delayed_set(:service, rdata) resource.import_update_or_skip(index: index, verbose: verbose, test: test) known_ids << resource.id end cleanup_except(project, known_ids) if project && cleanup known_ids end |
Instance Method Details
#created_at ⇒ Object
The created_at property
27 |
# File 'lib/skull_island/resources/route.rb', line 27 property :created_at, read_only: true, postprocess: true |
#destinations ⇒ Object
The destinations property
25 |
# File 'lib/skull_island/resources/route.rb', line 25 property :destinations |
#export(options = {}) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/AbcSize
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/skull_island/resources/route.rb', line 80 def export( = {}) hash = { 'name' => name, 'methods' => methods, 'paths' => paths, 'protocols' => protocols, 'hosts' => hosts, 'https_redirect_status_code' => https_redirect_status_code, 'regex_priority' => regex_priority, 'strip_path' => strip_path?, 'preserve_host' => preserve_host? } hash['service'] = "<%= lookup :service, '#{service.name}' %>" if service hash['snis'] = snis if snis && !snis.empty? hash['headers'] = headers if headers && !headers.empty? 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 |
#headers ⇒ Object
The headers property
16 |
# File 'lib/skull_island/resources/route.rb', line 16 property :headers, validate: true |
#hosts ⇒ Object
The hosts property
17 |
# File 'lib/skull_island/resources/route.rb', line 17 property :hosts, validate: true |
#https_redirect_status_code ⇒ Object
The https_redirect_status_code property
18 |
# File 'lib/skull_island/resources/route.rb', line 18 property :https_redirect_status_code, validate: true |
#methods ⇒ Object
The methods property
13 |
# File 'lib/skull_island/resources/route.rb', line 13 property :methods |
#modified_existing? ⇒ Boolean
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity rubocop:enable Metrics/AbcSize
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/skull_island/resources/route.rb', line 108 def modified_existing? return false unless new? # Find routes of the same name and service same_name_and_service = self.class.where(:name, name).and(:service, service) existing = same_name_and_service.size == 1 ? same_name_and_service.first : nil if existing @entity['id'] = existing.id save else false end end |
#name ⇒ Object
The name property
12 |
# File 'lib/skull_island/resources/route.rb', line 12 property :name |
#path_handling ⇒ Object
The path_handling property
23 |
# File 'lib/skull_island/resources/route.rb', line 23 property :path_handling, validate: true |
#paths ⇒ Object
The paths property
14 |
# File 'lib/skull_island/resources/route.rb', line 14 property :paths |
#plugins ⇒ Object
Provides a collection of related Plugin instances
73 74 75 |
# File 'lib/skull_island/resources/route.rb', line 73 def plugins Plugin.where(:route, self, api_client: api_client) end |
#preserve_host ⇒ Object
The preserve_host property
21 |
# File 'lib/skull_island/resources/route.rb', line 21 property :preserve_host, type: :boolean |
#protocols ⇒ Object
The protocols property
15 |
# File 'lib/skull_island/resources/route.rb', line 15 property :protocols, validate: true |
#regex_priority ⇒ Object
The regex_priority property
19 |
# File 'lib/skull_island/resources/route.rb', line 19 property :regex_priority, validate: true |
#service ⇒ Object
The service property
26 |
# File 'lib/skull_island/resources/route.rb', line 26 property :service, validate: true, preprocess: true, postprocess: true |
#snis ⇒ Object
The snis property
22 |
# File 'lib/skull_island/resources/route.rb', line 22 property :snis, validate: true |
#sources ⇒ Object
The sources property
24 |
# File 'lib/skull_island/resources/route.rb', line 24 property :sources |
#strip_path ⇒ Object
The strip_path property
20 |
# File 'lib/skull_island/resources/route.rb', line 20 property :strip_path, type: :boolean |
#tags ⇒ Object
The tags property
29 |
# File 'lib/skull_island/resources/route.rb', line 29 property :tags, validate: true, preprocess: true, postprocess: true |
#updated_at ⇒ Object
The updated_at property
28 |
# File 'lib/skull_island/resources/route.rb', line 28 property :updated_at, read_only: true, postprocess: true |