Skip to content

Commit

Permalink
RandomGenerator: UseLogger モジュールを使用する
Browse files Browse the repository at this point in the history
refs #67
  • Loading branch information
ochaochaocha3 committed May 16, 2016
1 parent d7efed3 commit b44ea83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions lib/rgrb/plugin/random_generator/generator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# vim: fileencoding=utf-8

require 'lumberjack'

require 'rgrb/plugin/configurable_generator'
require 'rgrb/plugin/use_logger'
require 'rgrb/plugin/random_generator/constants'
require 'rgrb/plugin/random_generator/table'
require 'rgrb/plugin/random_generator/table_not_found'
Expand All @@ -15,6 +14,7 @@ module RandomGenerator
# RandomGenerator の出力テキスト生成器
class Generator
include ConfigurableGenerator
include UseLogger

# 循環参照と見做される同一表参照回数の閾値
CIRCULAR_REFERENCE_THRESHOLD = 10
Expand All @@ -23,20 +23,19 @@ def initialize
super

@ramdom = Random.new
@logger = Lumberjack::Logger.new(
$stdout, progname: self.class.to_s
)
prepare_default_logger
end

# プラグインの設定を行う
#
# ランダムジェネレータでは、データを読み込む。
#
# @return [self]
def configure(*)
def configure(config_data)
super

load_data("#{@data_path}/**/*.yaml")
set_logger(config_data)

self
end
Expand Down Expand Up @@ -125,7 +124,7 @@ def replace_var_with_value(str, root_table)

if get_count[table] >= CIRCULAR_REFERENCE_THRESHOLD
# 同一表の参照上限に到達したので、打ち切る
@logger.warn("参照上限到達: #{table}")
logger.warn("参照上限到達: #{table}")
next '(...)'
end

Expand Down Expand Up @@ -160,8 +159,8 @@ def load_data(glob_pattern)

@table[table.name] = table
rescue => e
@logger.error("データファイル #{path} の読み込みに失敗しました")
@logger.error(e)
logger.error("データファイル #{path} の読み込みに失敗しました")
logger.error(e)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rgrb/plugin/random_generator/irc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class IrcAdapter
match(/rg-info#{SPACES_RE}#{TABLES_RE}/o, method: :info)
match(/rg-list/, method: :list)

def initialize(*args)
def initialize(*)
super

config_data = config[:plugin] || {}
config_data = config[:plugin]
@list_reply = config_data['ListReply'] || ''

prepare_generator
Expand Down

0 comments on commit b44ea83

Please sign in to comment.