Class: TRMNLP::Config::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/trmnlp/config/plugin.rb

Instance Method Summary collapse

Constructor Details

#initialize(paths, project_config) ⇒ Plugin

Returns a new instance of Plugin.



6
7
8
9
10
# File 'lib/trmnlp/config/plugin.rb', line 6

def initialize(paths, project_config)
  @paths = paths
  @project_config = project_config
  reload!
end

Instance Method Details

#dark_modeObject



46
# File 'lib/trmnlp/config/plugin.rb', line 46

def dark_mode = @config['dark_mode'] || 'no'

#idObject



50
# File 'lib/trmnlp/config/plugin.rb', line 50

def id = @config['id']

#no_screen_paddingObject



48
# File 'lib/trmnlp/config/plugin.rb', line 48

def no_screen_padding = @config['no_screen_padding'] || 'no'

#polling?Boolean

Returns:

  • (Boolean)


21
# File 'lib/trmnlp/config/plugin.rb', line 21

def polling? = strategy == 'polling'

#polling_bodyObject



44
# File 'lib/trmnlp/config/plugin.rb', line 44

def polling_body = with_custom_fields(@config['polling_body'] || '')

#polling_headersObject



38
39
40
# File 'lib/trmnlp/config/plugin.rb', line 38

def polling_headers
  string_to_hash(@config['polling_headers'] || '').transform_values { |v| with_custom_fields(v) }
end

#polling_headers_encodedObject

for trmnl }



42
# File 'lib/trmnlp/config/plugin.rb', line 42

def polling_headers_encoded = polling_headers.map { |k, v| "#{k}=#{v}" }.join('&') # for {{ trmnl }}

#polling_url_textObject

for trmnl }



34
# File 'lib/trmnlp/config/plugin.rb', line 34

def polling_url_text = polling_urls.join("\r\n") # for {{ trmnl }}

#polling_urlsObject



25
26
27
28
29
30
31
32
# File 'lib/trmnlp/config/plugin.rb', line 25

def polling_urls
  # allow project-level config to override
  urls = project_config.user_data_overrides.dig('trmnl', 'plugin_settings', 'polling_url') || @config['polling_url']

  return [] if urls.nil?

  urls.strip.split("\n").map { |url| with_custom_fields(url.strip) }
end

#polling_verbObject



36
# File 'lib/trmnlp/config/plugin.rb', line 36

def polling_verb = @config['polling_verb'] || 'GET'

#reload!Object



12
13
14
15
16
17
18
# File 'lib/trmnlp/config/plugin.rb', line 12

def reload!
  if paths.plugin_config.exist?
    @config = YAML.load_file(paths.plugin_config)
  else
    @config = {}
  end
end

#static?Boolean

Returns:

  • (Boolean)


23
# File 'lib/trmnlp/config/plugin.rb', line 23

def static? = strategy == 'static'

#static_dataObject



52
53
54
55
56
# File 'lib/trmnlp/config/plugin.rb', line 52

def static_data
  JSON.parse(@config['static_data'] || '{}')
rescue JSON::ParserError
  raise Error, 'invalid JSON in static_data'
end

#strategyObject



20
# File 'lib/trmnlp/config/plugin.rb', line 20

def strategy = @config['strategy']

#webhook?Boolean

Returns:

  • (Boolean)


22
# File 'lib/trmnlp/config/plugin.rb', line 22

def webhook? = strategy == 'webhook'