Class: Codeball::Destination
- Inherits:
-
Object
- Object
- Codeball::Destination
- Defined in:
- lib/codeball/destination.rb
Overview
A filesystem context that writes entries to an output directory.
Destination decorates a directory path with the ability to receive codeball entries. It owns path safety validation, parent directory creation, and dry-run simulation.
Tracks outcomes internally and provides a summary when asked.
Constant Summary collapse
- DANGEROUS_PATTERNS =
[ /\A\.\./, %r{/\.\.}, %r{\A/}, /\A~/, ].freeze
Instance Attribute Summary collapse
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
Instance Method Summary collapse
- #dry_run? ⇒ Boolean
-
#initialize(output_dir = ".", dry_run: false) ⇒ Destination
constructor
A new instance of Destination.
- #summary(malformed: 0) ⇒ Object
- #write(entry) {|outcome| ... } ⇒ Object
Constructor Details
#initialize(output_dir = ".", dry_run: false) ⇒ Destination
Returns a new instance of Destination.
22 23 24 25 26 |
# File 'lib/codeball/destination.rb', line 22 def initialize(output_dir = ".", dry_run: false) @output_dir = Pathname.new(output_dir). @dry_run = dry_run ? true : false @results = [] end |
Instance Attribute Details
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
20 21 22 |
# File 'lib/codeball/destination.rb', line 20 def output_dir @output_dir end |
Instance Method Details
#dry_run? ⇒ Boolean
28 |
# File 'lib/codeball/destination.rb', line 28 def dry_run? = @dry_run |
#summary(malformed: 0) ⇒ Object
37 38 39 |
# File 'lib/codeball/destination.rb', line 37 def summary(malformed: 0) ExtractionSummary.new(@results, malformed: malformed) end |
#write(entry) {|outcome| ... } ⇒ Object
30 31 32 33 34 35 |
# File 'lib/codeball/destination.rb', line 30 def write(entry) outcome = write_entry(entry) @results << outcome yield outcome if block_given? outcome end |