Class: Rossoc::Backend
- Inherits:
-
Object
- Object
- Rossoc::Backend
- Defined in:
- lib/rossoc/backend.rb
Overview
Backend
Defined Under Namespace
Classes: BackendError
Constant Summary collapse
- RESERVED_TABLES =
%w[mruby arduino dev].freeze
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(ir, output, overwrite_enable) ⇒ Backend
constructor
A new instance of Backend.
- #write ⇒ Object
Constructor Details
#initialize(ir, output, overwrite_enable) ⇒ Backend
13 14 15 16 17 18 |
# File 'lib/rossoc/backend.rb', line 13 def initialize(ir, output, overwrite_enable) @ir = ir @output = output @content = nil @overwrite_enable = overwrite_enable end |
Instance Method Details
#generate ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rossoc/backend.rb', line 20 def generate table = @ir[:table] raise BackendError, "unknown table value #{table}." if RESERVED_TABLES.index(table).nil? template = ERB.new( File.read("#{__dir__}#{File::SEPARATOR}views#{File::SEPARATOR}#{table}.erb"), trim_mode: 2 ) @content = template.result_with_hash(@ir) end |
#write ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rossoc/backend.rb', line 32 def write raise BackendError, 'No content.' if @content.nil? if @output.blank? # ファイルが指定されていないとき標準出力 puts @content else raise BackendError, "File exists #{@output}." if File.exist?(@output) && !@overwrite_enable file = File.open(@output, 'w') file.write(@content) file.close end end |