Class: StandupMD::Config::Post
- Inherits:
-
Object
- Object
- StandupMD::Config::Post
- Defined in:
- lib/standup_md/config/post.rb
Overview
The configuration class for chat posting.
Constant Summary collapse
- DEFAULTS =
The default posting options.
{ default_adapter: :slack, title: nil }.freeze
- CONFIG_ATTRIBUTES =
Attributes copied into request-scoped config snapshots.
DEFAULTS.keys.freeze
Instance Attribute Summary collapse
-
#adapter_options ⇒ Hash
readonly
Non-secret adapter options.
-
#adapters ⇒ Hash
readonly
Registered adapter classes or instances.
-
#default_adapter ⇒ Symbol
The adapter used when ‘standup –post` is called without a platform.
-
#title ⇒ String?
Format string for posted entry titles.
Instance Method Summary collapse
-
#build_adapter(name = nil) ⇒ Object
Builds the adapter requested by name.
-
#configure_adapter(name, options = {}) ⇒ Hash
Configures non-secret adapter options.
-
#copy_from(config) ⇒ StandupMD::Config::Post
Copies values from another post config.
-
#initialize ⇒ Post
constructor
Initializes the config with default values.
-
#options_for(name) ⇒ Hash
Returns non-secret options for an adapter.
-
#register_adapter(name, adapter) ⇒ Class, Object
Registers a posting adapter.
-
#reset ⇒ Hash
Sets all config values back to their defaults.
Constructor Details
#initialize ⇒ Post
Initializes the config with default values.
60 61 62 |
# File 'lib/standup_md/config/post.rb', line 60 def initialize reset end |
Instance Attribute Details
#adapter_options ⇒ Hash (readonly)
Non-secret adapter options.
56 57 58 |
# File 'lib/standup_md/config/post.rb', line 56 def @adapter_options end |
#adapters ⇒ Hash (readonly)
Registered adapter classes or instances.
50 51 52 |
# File 'lib/standup_md/config/post.rb', line 50 def adapters @adapters end |
#default_adapter ⇒ Symbol
The adapter used when ‘standup –post` is called without a platform.
29 30 31 |
# File 'lib/standup_md/config/post.rb', line 29 def default_adapter @default_adapter end |
#title ⇒ String?
Format string for posted entry titles.
This only affects messages sent through chat posting adapters. It does not change stored standup markdown files. Use ‘%s` as a placeholder for the normal entry title, such as the entry date. This is useful when chat clients post through workspace apps or bots with shared names like “StandupMD”, but the message should still identify whose standup it is.
44 45 46 |
# File 'lib/standup_md/config/post.rb', line 44 def title @title end |
Instance Method Details
#build_adapter(name = nil) ⇒ Object
Builds the adapter requested by name.
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/standup_md/config/post.rb', line 132 def build_adapter(name = nil) adapter_name = (name || default_adapter).to_sym adapter = adapters.fetch(adapter_name) do raise StandupMD::Post::UnknownAdapter, "No post adapter registered for #{adapter_name}" end return adapter unless adapter.respond_to?(:new) return adapter.new if adapter.instance_method(:initialize).arity.zero? adapter.new((adapter_name)) end |
#configure_adapter(name, options = {}) ⇒ Hash
Configures non-secret adapter options.
112 113 114 |
# File 'lib/standup_md/config/post.rb', line 112 def configure_adapter(name, = {}) (name).merge!(symbolize_keys()) end |
#copy_from(config) ⇒ StandupMD::Config::Post
Copies values from another post config.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/standup_md/config/post.rb', line 82 def copy_from(config) CONFIG_ATTRIBUTES.each do |attribute| instance_variable_set("@#{attribute}", config.public_send(attribute)) end @adapters = config.adapters.dup @adapter_options = Hash.new { |hash, key| hash[key] = {} } config..each do |name, | @adapter_options[name] = .dup end self end |
#options_for(name) ⇒ Hash
Returns non-secret options for an adapter.
122 123 124 |
# File 'lib/standup_md/config/post.rb', line 122 def (name) [name.to_sym] end |
#register_adapter(name, adapter) ⇒ Class, Object
Registers a posting adapter.
101 102 103 |
# File 'lib/standup_md/config/post.rb', line 101 def register_adapter(name, adapter) adapters[name.to_sym] = adapter end |
#reset ⇒ Hash
Sets all config values back to their defaults.
68 69 70 71 72 73 74 |
# File 'lib/standup_md/config/post.rb', line 68 def reset DEFAULTS.each { |k, v| instance_variable_set("@#{k}", v) } @adapters = {} @adapter_options = Hash.new { |hash, key| hash[key] = {} } register_adapter(:slack, StandupMD::Post::Adapters::Slack) DEFAULTS end |