Class: Rufio::DslCommandLoader
- Inherits:
-
Object
- Object
- Rufio::DslCommandLoader
- Defined in:
- lib/rufio/dsl_command_loader.rb
Overview
DSL設定ファイルを読み込んでDslCommandを生成するクラス
Defined Under Namespace
Classes: CommandBuilder, DslContext
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#default_config_paths ⇒ Array<String>
デフォルトの設定ファイルパスを返す.
-
#initialize ⇒ DslCommandLoader
constructor
A new instance of DslCommandLoader.
-
#load ⇒ Array<DslCommand>
デフォルトのパスからDSLをロードする.
-
#load_from_file(file_path) ⇒ Array<DslCommand>
ファイルからDSLをロードする.
-
#load_from_paths(paths) ⇒ Array<DslCommand>
複数のパスからDSLをロードする.
-
#load_from_string(dsl_string) ⇒ Array<DslCommand>
文字列からDSLを解析してコマンドをロードする.
Constructor Details
#initialize ⇒ DslCommandLoader
Returns a new instance of DslCommandLoader.
8 9 10 11 |
# File 'lib/rufio/dsl_command_loader.rb', line 8 def initialize @errors = [] @warnings = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/rufio/dsl_command_loader.rb', line 6 def errors @errors end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
6 7 8 |
# File 'lib/rufio/dsl_command_loader.rb', line 6 def warnings @warnings end |
Instance Method Details
#default_config_paths ⇒ Array<String>
デフォルトの設定ファイルパスを返す
68 69 70 71 72 73 74 |
# File 'lib/rufio/dsl_command_loader.rb', line 68 def default_config_paths home = Dir.home [ File.join(home, ".rufio", "commands.rb"), File.join(home, ".config", "rufio", "commands.rb") ] end |
#load ⇒ Array<DslCommand>
デフォルトのパスからDSLをロードする
62 63 64 |
# File 'lib/rufio/dsl_command_loader.rb', line 62 def load load_from_paths(default_config_paths) end |
#load_from_file(file_path) ⇒ Array<DslCommand>
ファイルからDSLをロードする
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rufio/dsl_command_loader.rb', line 34 def load_from_file(file_path) @errors = [] @warnings = [] = File.(file_path) unless File.exist?() return [] end content = File.read() load_from_string(content) end |
#load_from_paths(paths) ⇒ Array<DslCommand>
複数のパスからDSLをロードする
50 51 52 53 54 55 56 57 58 |
# File 'lib/rufio/dsl_command_loader.rb', line 50 def load_from_paths(paths) commands = [] paths.each do |path| commands.concat(load_from_file(path)) end commands end |
#load_from_string(dsl_string) ⇒ Array<DslCommand>
文字列からDSLを解析してコマンドをロードする
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rufio/dsl_command_loader.rb', line 16 def load_from_string(dsl_string) @errors = [] @warnings = [] context = DslContext.new begin context.instance_eval(dsl_string) rescue SyntaxError, StandardError => e @errors << "DSL parse error: #{e.}" return [] end validate_commands(context.commands) end |