Class: SkullIsland::Resources::Route

Inherits:
SkullIsland::Resource show all
Defined in:
lib/skull_island/resources/route.rb

Overview

The Route resource class

Instance Attribute Summary

Attributes inherited from SkullIsland::Resource

#api_client, #entity, #errors

Class Method Summary collapse

Instance Method Summary collapse

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/skull_island/resources/route.rb', line 29

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.methods = rdata['methods'] if rdata['methods']
    resource.paths = rdata['paths'] if rdata['paths']
    resource.protocols = rdata['protocols'] if rdata['protocols']
    resource.hosts = rdata['hosts'] if rdata['hosts']
    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.snis = rdata['snis'] if rdata['snis']
    resource.tags = rdata['tags'] if rdata['tags']
    resource.delayed_set(:service, rdata, 'service')
    resource.import_update_or_skip(index: index, verbose: verbose, test: test)
  end
end

Instance Method Details

#created_atObject

The created_at property



22
# File 'lib/skull_island/resources/route.rb', line 22

property :created_at, read_only: true, postprocess: true

#destinationsObject

The destinations property



20
# File 'lib/skull_island/resources/route.rb', line 20

property :destinations

#export(options = {}) ⇒ Object

rubocop:disable Metrics/AbcSize



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/skull_island/resources/route.rb', line 58

def export(options = {})
  hash = {
    'name' => name,
    'methods' => methods,
    'paths' => paths,
    'protocols' => protocols,
    'hosts' => hosts,
    '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['tags'] = tags if tags
  [*options[:exclude]].each do |exclude|
    hash.delete(exclude.to_s)
  end
  [*options[:include]].each do |inc|
    hash[inc.to_s] = send(inc.to_sym)
  end
  hash.reject { |_, value| value.nil? }
end

#hostsObject

The hosts property



14
# File 'lib/skull_island/resources/route.rb', line 14

property :hosts,          validate: true

#methodsObject

The methods property



11
# File 'lib/skull_island/resources/route.rb', line 11

property :methods

#modified_existing?Boolean

rubocop:enable Metrics/AbcSize

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/skull_island/resources/route.rb', line 82

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

#nameObject

The name property



10
# File 'lib/skull_island/resources/route.rb', line 10

property :name

#pathsObject

The paths property



12
# File 'lib/skull_island/resources/route.rb', line 12

property :paths

#pluginsObject

Provides a collection of related Plugin instances



53
54
55
# File 'lib/skull_island/resources/route.rb', line 53

def plugins
  Plugin.where(:route, self, api_client: api_client)
end

#preserve_hostObject

The preserve_host property



17
# File 'lib/skull_island/resources/route.rb', line 17

property :preserve_host,  type: :boolean

#protocolsObject

The protocols property



13
# File 'lib/skull_island/resources/route.rb', line 13

property :protocols,      validate: true

#regex_priorityObject

The regex_priority property



15
# File 'lib/skull_island/resources/route.rb', line 15

property :regex_priority, validate: true

#serviceObject

The service property



21
# File 'lib/skull_island/resources/route.rb', line 21

property :service, validate: true, preprocess: true, postprocess: true

#snisObject

The snis property



18
# File 'lib/skull_island/resources/route.rb', line 18

property :snis,           validate: true

#sourcesObject

The sources property



19
# File 'lib/skull_island/resources/route.rb', line 19

property :sources

#strip_pathObject

The strip_path property



16
# File 'lib/skull_island/resources/route.rb', line 16

property :strip_path,     type: :boolean

#tagsObject

The tags property



24
# File 'lib/skull_island/resources/route.rb', line 24

property :tags, validate: true

#updated_atObject

The updated_at property



23
# File 'lib/skull_island/resources/route.rb', line 23

property :updated_at, read_only: true, postprocess: true