Class: SkullIsland::Resources::Plugin
- Inherits:
-
SkullIsland::Resource
- Object
- SkullIsland::Resource
- SkullIsland::Resources::Plugin
- Includes:
- Helpers::Meta
- Defined in:
- lib/skull_island/resources/plugin.rb
Overview
The Plugin 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) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
-
.enabled_names(api_client: APIClient.instance) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity.
- .schema(name, api_client: APIClient.instance) ⇒ Object
Instance Method Summary collapse
-
#config ⇒ Object
The config property.
-
#consumer ⇒ Object
The consumer property.
-
#created_at ⇒ Object
The created_at property.
- #digest_properties ⇒ Object
-
#enabled ⇒ Object
The enabled property.
- #export(options = {}) ⇒ Object
-
#modified_existing? ⇒ Boolean
rubocop:disable Metrics/PerceivedComplexity.
-
#name ⇒ Object
The name property.
-
#route ⇒ Object
The route property.
-
#run_on ⇒ Object
The run_on property.
-
#service ⇒ Object
The service property.
-
#tags ⇒ Object
The tags 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, #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, #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) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/skull_island/resources/plugin.rb', line 24 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.name = resource_data['name'] resource.enabled = resource_data['enabled'] resource.run_on = resource_data['run_on'] if resource_data['run_on'] resource.config = resource_data['config'].deep_sort if resource_data['config'] 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.delayed_set(:consumer, resource_data, 'consumer') resource.delayed_set(:route, resource_data, 'route') resource.delayed_set(:service, resource_data, 'service') resource.import_update_or_skip(index: index, verbose: verbose, test: test) known_ids << resource.id end cleanup_except(project, known_ids) if project end |
.enabled_names(api_client: APIClient.instance) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity
50 51 52 |
# File 'lib/skull_island/resources/plugin.rb', line 50 def self.enabled_names(api_client: APIClient.instance) api_client.get("#{relative_uri}/enabled")['enabled_plugins'] end |
.schema(name, api_client: APIClient.instance) ⇒ Object
54 55 56 |
# File 'lib/skull_island/resources/plugin.rb', line 54 def self.schema(name, api_client: APIClient.instance) api_client.get("#{relative_uri}/schema/#{name}") end |
Instance Method Details
#config ⇒ Object
The config property
15 |
# File 'lib/skull_island/resources/plugin.rb', line 15 property :config, validate: true, preprocess: true, postprocess: true |
#consumer ⇒ Object
The consumer property
16 |
# File 'lib/skull_island/resources/plugin.rb', line 16 property :consumer, validate: true, preprocess: true, postprocess: true |
#created_at ⇒ Object
The created_at property
19 |
# File 'lib/skull_island/resources/plugin.rb', line 19 property :created_at, read_only: true, postprocess: true |
#digest_properties ⇒ Object
58 59 60 |
# File 'lib/skull_island/resources/plugin.rb', line 58 def digest_properties super.reject { |k| %i[run_on].include? k } end |
#enabled ⇒ Object
The enabled property
13 |
# File 'lib/skull_island/resources/plugin.rb', line 13 property :enabled, type: :boolean |
#export(options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/skull_island/resources/plugin.rb', line 62 def export( = {}) hash = { 'name' => name, 'enabled' => enabled?, 'config' => config.deep_sort } hash['consumer'] = "<%= lookup :consumer, '#{consumer.username}' %>" if consumer hash['route'] = "<%= lookup :route, '#{route.name}' %>" if route hash['service'] = "<%= lookup :service, '#{service.name}' %>" if service 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 |
#modified_existing? ⇒ Boolean
rubocop:disable Metrics/PerceivedComplexity
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/skull_island/resources/plugin.rb', line 82 def modified_existing? return false unless new? # Find plugins of the same name same_name = self.class.where(:name, name) return false if same_name.size.zero? same_name_and_consumer = same_name.where(:consumer, consumer) same_name_and_route = same_name.where(:route, route) same_name_and_service = same_name.where(:service, service) existing = if same_name_and_consumer.size == 1 same_name_and_consumer.first elsif same_name_and_route.size == 1 same_name_and_route.first elsif same_name_and_service.size == 1 same_name_and_service.first end if existing @entity['id'] = existing.id save else false end end |
#name ⇒ Object
The name property
12 |
# File 'lib/skull_island/resources/plugin.rb', line 12 property :name |
#route ⇒ Object
The route property
17 |
# File 'lib/skull_island/resources/plugin.rb', line 17 property :route, validate: true, preprocess: true, postprocess: true |
#run_on ⇒ Object
The run_on property
14 |
# File 'lib/skull_island/resources/plugin.rb', line 14 property :run_on, validate: true |
#service ⇒ Object
The service property
18 |
# File 'lib/skull_island/resources/plugin.rb', line 18 property :service, validate: true, preprocess: true, postprocess: true |
#tags ⇒ Object
The tags property
20 |
# File 'lib/skull_island/resources/plugin.rb', line 20 property :tags, validate: true, preprocess: true, postprocess: true |