Class: QuestionCompiler::LocalQuestionWriter
- Inherits:
-
Object
- Object
- QuestionCompiler::LocalQuestionWriter
- Defined in:
- lib/question_compiler/local.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
Instance Method Summary collapse
-
#initialize(root, question_path) ⇒ LocalQuestionWriter
constructor
Pass the path to the compiled folder.
- #open ⇒ Object
-
#write(sub_path, data) ⇒ Object
Given a path within the question such as ‘assets/style.css` and the data, writes the file.
Constructor Details
#initialize(root, question_path) ⇒ LocalQuestionWriter
Pass the path to the compiled folder. I.e. the folder whose children are question names.
52 53 54 55 |
# File 'lib/question_compiler/local.rb', line 52 def initialize(root, question_path) @root = root @question_path = question_path end |
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
57 58 59 |
# File 'lib/question_compiler/local.rb', line 57 def log @log end |
Instance Method Details
#open ⇒ Object
59 60 61 62 63 |
# File 'lib/question_compiler/local.rb', line 59 def open # This is basically a no-op. Some other question writer implementations may need to # open and close the question as a whole. yield end |
#write(sub_path, data) ⇒ Object
Given a path within the question such as ‘assets/style.css` and the data, writes the file. Returns true if the file was written successfully. Returns false is the file was unwritable.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/question_compiler/local.rb', line 68 def write(sub_path, data) path = File.(File.join(@root, @question_path, sub_path)) @log.debug "W: #{path} (#{data.length} bytes)" begin FileUtils.mkdir_p File.dirname(path) File.open(path, 'w') do |f| f << data end true rescue Exception fail_write path end end |