Class: TRMNLP::Config::Plugin
- Inherits:
-
Object
- Object
- TRMNLP::Config::Plugin
- Defined in:
- lib/trmnlp/config/plugin.rb
Instance Method Summary collapse
- #dark_mode ⇒ Object
- #id ⇒ Object
-
#initialize(paths, project_config) ⇒ Plugin
constructor
A new instance of Plugin.
- #no_screen_padding ⇒ Object
- #polling? ⇒ Boolean
- #polling_body ⇒ Object
- #polling_headers ⇒ Object
-
#polling_headers_encoded ⇒ Object
for trmnl }.
-
#polling_url_text ⇒ Object
for trmnl }.
- #polling_urls ⇒ Object
- #polling_verb ⇒ Object
- #reload! ⇒ Object
- #static? ⇒ Boolean
- #static_data ⇒ Object
- #strategy ⇒ Object
- #webhook? ⇒ Boolean
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_mode ⇒ Object
46 |
# File 'lib/trmnlp/config/plugin.rb', line 46 def dark_mode = @config['dark_mode'] || 'no' |
#id ⇒ Object
50 |
# File 'lib/trmnlp/config/plugin.rb', line 50 def id = @config['id'] |
#no_screen_padding ⇒ Object
48 |
# File 'lib/trmnlp/config/plugin.rb', line 48 def no_screen_padding = @config['no_screen_padding'] || 'no' |
#polling? ⇒ Boolean
21 |
# File 'lib/trmnlp/config/plugin.rb', line 21 def polling? = strategy == 'polling' |
#polling_body ⇒ Object
44 |
# File 'lib/trmnlp/config/plugin.rb', line 44 def polling_body = with_custom_fields(@config['polling_body'] || '') |
#polling_headers ⇒ Object
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_encoded ⇒ Object
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_text ⇒ Object
for trmnl }
34 |
# File 'lib/trmnlp/config/plugin.rb', line 34 def polling_url_text = polling_urls.join("\r\n") # for {{ trmnl }} |
#polling_urls ⇒ Object
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_verb ⇒ Object
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
23 |
# File 'lib/trmnlp/config/plugin.rb', line 23 def static? = strategy == 'static' |
#static_data ⇒ Object
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 |
#strategy ⇒ Object
20 |
# File 'lib/trmnlp/config/plugin.rb', line 20 def strategy = @config['strategy'] |
#webhook? ⇒ Boolean
22 |
# File 'lib/trmnlp/config/plugin.rb', line 22 def webhook? = strategy == 'webhook' |