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, trmnlp_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, trmnlp_config) ⇒ Plugin
Returns a new instance of Plugin.
6 7 8 9 10 |
# File 'lib/trmnlp/config/plugin.rb', line 6 def initialize(paths, trmnlp_config) @paths = paths @trmnlp_config = trmnlp_config reload! end |
Instance Method Details
#dark_mode ⇒ Object
45 |
# File 'lib/trmnlp/config/plugin.rb', line 45 def dark_mode = @config['dark_mode'] || 'no' |
#id ⇒ Object
49 |
# File 'lib/trmnlp/config/plugin.rb', line 49 def id = @config['id'] |
#no_screen_padding ⇒ Object
47 |
# File 'lib/trmnlp/config/plugin.rb', line 47 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
43 |
# File 'lib/trmnlp/config/plugin.rb', line 43 def polling_body = with_custom_fields(@config['polling_body'] || '') |
#polling_headers ⇒ Object
37 38 39 |
# File 'lib/trmnlp/config/plugin.rb', line 37 def polling_headers string_to_hash(@config['polling_headers'] || '').transform_values { |v| with_custom_fields(v) } end |
#polling_headers_encoded ⇒ Object
for trmnl }
41 |
# File 'lib/trmnlp/config/plugin.rb', line 41 def polling_headers_encoded = polling_headers.map { |k, v| "#{k}=#{v}" }.join('&') # for {{ trmnl }} |
#polling_url_text ⇒ Object
for trmnl }
33 |
# File 'lib/trmnlp/config/plugin.rb', line 33 def polling_url_text = polling_urls.join("\r\n") # for {{ trmnl }} |
#polling_urls ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/trmnlp/config/plugin.rb', line 25 def polling_urls return [] if @config['polling_url'].nil? || @config['polling_url'].empty? urls = @config['polling_url'].split("\n").map(&:strip) urls.map { |url| with_custom_fields(url) } end |
#polling_verb ⇒ Object
35 |
# File 'lib/trmnlp/config/plugin.rb', line 35 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
51 52 53 54 55 |
# File 'lib/trmnlp/config/plugin.rb', line 51 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' |