Module: SkullIsland::Helpers::Meta
- Included in:
- Resources::CACertificate, Resources::Certificate, Resources::Consumer, Resources::Plugin, Resources::Route, Resources::Service, Resources::Upstream, Resources::UpstreamTarget
- Defined in:
- lib/skull_island/helpers/meta.rb
Overview
Useful for embedding meta-data into special tags
Instance Method Summary collapse
- #add_meta(key, value) ⇒ Object
- #import_time ⇒ Object
- #import_time=(time) ⇒ Object
- #metatags ⇒ Object
- #postprocess_tags(value) ⇒ Object
- #preprocess_tags(input) ⇒ Object
- #project ⇒ Object
- #project=(project_id) ⇒ Object
- #raw_tags ⇒ Object
- #remove_meta(key) ⇒ Object
- #supports_meta? ⇒ Boolean
Instance Method Details
#add_meta(key, value) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/skull_island/helpers/meta.rb', line 7 def (key, value) = "_meta~#{key}~#{value}" # filter out any existing duplicate metatags = .reject { |tag| tag.start_with?("_meta~#{key}~") } # Add the new tag directly, bypassing preprocessing raw_set('tags', + []) end |
#import_time ⇒ Object
17 18 19 |
# File 'lib/skull_island/helpers/meta.rb', line 17 def import_time ['import_time'] end |
#import_time=(time) ⇒ Object
21 22 23 |
# File 'lib/skull_island/helpers/meta.rb', line 21 def import_time=(time) ('import_time', time) end |
#metatags ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/skull_island/helpers/meta.rb', line 33 def = {} .select { |tag| tag.start_with?('_meta~') }.each do |tag| key, value = tag.gsub('_meta~', '').split('~', 2) [key] = value end end |
#postprocess_tags(value) ⇒ Object
63 64 65 |
# File 'lib/skull_island/helpers/meta.rb', line 63 def (value) (value || []).reject { |tag| tag.start_with?('_meta~') } end |
#preprocess_tags(input) ⇒ Object
59 60 61 |
# File 'lib/skull_island/helpers/meta.rb', line 59 def (input) input.uniq + .map { |k, v| "_meta~#{k}~#{v}" } end |
#project ⇒ Object
42 43 44 |
# File 'lib/skull_island/helpers/meta.rb', line 42 def project ['project'] end |
#project=(project_id) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/skull_island/helpers/meta.rb', line 46 def project=(project_id) unless project_id.is_a?(String) && project_id.match?(/^[\w_\-.~]+$/) raise Exceptions::InvalidArguments, 'project' end ('project', project_id) end |
#raw_tags ⇒ Object
54 55 56 57 |
# File 'lib/skull_island/helpers/meta.rb', line 54 def reload if @lazy && !@entity.key?('tags') @entity['tags'] || [] end |
#remove_meta(key) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/skull_island/helpers/meta.rb', line 25 def (key) # filter out an existing metatags = .reject { |tag| tag.start_with?("_meta~#{key}~") } # Bypassing preprocessing raw_set('tags', ) end |
#supports_meta? ⇒ Boolean
67 68 69 |
# File 'lib/skull_island/helpers/meta.rb', line 67 def true end |