Skip to content

Commit

Permalink
Merge d900dc6 into 6ad3916
Browse files Browse the repository at this point in the history
  • Loading branch information
koi-chan committed Jul 23, 2019
2 parents 6ad3916 + d900dc6 commit 2da923e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
12 changes: 7 additions & 5 deletions lib/rgrb/exec/discord_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'rgrb/version'
require 'rgrb/config'
require 'rgrb/plugins_loader'
require 'rgrb/plugin_base/adapter_options'

module RGRB
module Exec
Expand Down Expand Up @@ -98,11 +99,12 @@ def extract_plugin_options(
plugin_name = adapter.plugin_name
plugin_config = config.plugin_config[plugin_name] || {}

plugin_options[adapter] = {
root_path: root_path,
plugin: plugin_config,
config_id: config.id
}
plugin_options[adapter] = PluginBase::AdapterOptions.new(
config.id,
root_path,
plugin_config,
logger
)

logger.warn(
"プラグイン #{plugin_name} の設定を読み込みました"
Expand Down
13 changes: 7 additions & 6 deletions lib/rgrb/exec/irc_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'rgrb/version'
require 'rgrb/config'
require 'rgrb/plugins_loader'
require 'rgrb/plugin_base/adapter_options'

module RGRB
module Exec
Expand Down Expand Up @@ -98,12 +99,12 @@ def extract_plugin_options(
plugin_name = adapter.plugin_name
plugin_config = config.plugin_config[plugin_name] || {}

plugin_options[adapter] = {
root_path: root_path,
plugin: plugin_config,
config_id: config.id,
logger: logger
}
plugin_options[adapter] = PluginBase::AdapterOptions.new(
config.id,
root_path,
plugin_config,
logger
)

logger.warn(
"プラグイン #{plugin_name} の設定を読み込みました"
Expand Down
8 changes: 4 additions & 4 deletions lib/rgrb/plugin_base/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def prepare_generator
generator_class = Object.const_get(class_name_tree.join('::'))
@generator = generator_class.new

@generator.config_id = config[:config_id]
@generator.root_path = config[:root_path]
@generator.logger = config[:logger]
@generator.config_id = config.id
@generator.root_path = config.root_path
@generator.logger = config.logger

# プラグインをロガーとして使えるよう、設定に含める
config_data = config[:plugin].merge({ logger: self })
config_data = config.plugin.merge({ logger: self })
@generator.configure(config_data)

true
Expand Down
12 changes: 12 additions & 0 deletions lib/rgrb/plugin_base/adapter_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# vim: fileencoding=utf-8

module RGRB
module PluginBase
AdapterOptions = Struct.new(
:id,
:root_path,
:plugin,
:logger,
)
end
end
13 changes: 8 additions & 5 deletions spec/rgrb/plugin/configurable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

require 'rgrb/plugin_base/generator'
require 'rgrb/plugin_base/adapter'
require 'rgrb/plugin_base/adapter_options'

module RGRB
module Plugin
Expand All @@ -28,12 +29,14 @@ class IrcAdapter
attr_reader :generator

def config
{
root_path: '/home/rgrb',
plugin: {
PluginBase::AdapterOptions.new(
'test',
'/home/rgrb',
{
'name' => 'RGRB'
}
}
},
Lumberjack::Logger.new($stdout, progname: self.class.to_s)
)
end
end
end
Expand Down

0 comments on commit 2da923e

Please sign in to comment.