Module: SkullIsland::Helpers::Meta

Overview

Useful for embedding meta-data into special tags

Instance Method Summary collapse

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 add_meta(key, value)
  metatag = "_meta~#{key}~#{value}"

  # filter out any existing duplicate metatags
  existing_tags = raw_tags.reject { |tag| tag.start_with?("_meta~#{key}~") }

  # Add the new tag directly, bypassing preprocessing
  raw_set('tags', existing_tags + [metatag])
end

#import_timeObject



17
18
19
# File 'lib/skull_island/helpers/meta.rb', line 17

def import_time
  metatags['import_time']
end

#import_time=(time) ⇒ Object



21
22
23
# File 'lib/skull_island/helpers/meta.rb', line 21

def import_time=(time)
  add_meta('import_time', time)
end

#metatagsObject



33
34
35
36
37
38
39
40
# File 'lib/skull_island/helpers/meta.rb', line 33

def metatags
   = {}
  raw_tags.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 postprocess_tags(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 preprocess_tags(input)
  input.uniq + metatags.map { |k, v| "_meta~#{k}~#{v}" }
end

#projectObject



42
43
44
# File 'lib/skull_island/helpers/meta.rb', line 42

def project
  metatags['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

  add_meta('project', project_id)
end

#raw_tagsObject



54
55
56
57
# File 'lib/skull_island/helpers/meta.rb', line 54

def raw_tags
  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 remove_meta(key)
  # filter out an existing metatags
  filtered_tags = raw_tags.reject { |tag| tag.start_with?("_meta~#{key}~") }

  # Bypassing preprocessing
  raw_set('tags', filtered_tags)
end

#supports_meta?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/skull_island/helpers/meta.rb', line 67

def supports_meta?
  true
end