Class: Cukehead::FeatureWriter
- Inherits:
-
Object
- Object
- Cukehead::FeatureWriter
- Defined in:
- lib/cukehead/feature_writer.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#overwrite ⇒ Object
Returns the value of attribute overwrite.
Instance Method Summary collapse
-
#initialize ⇒ FeatureWriter
constructor
A new instance of FeatureWriter.
-
#write_features(features) ⇒ Object
Writes feature files to the location specified by :output_path.
Constructor Details
#initialize ⇒ FeatureWriter
Returns a new instance of FeatureWriter.
9 10 11 12 13 |
# File 'lib/cukehead/feature_writer.rb', line 9 def initialize @output_path = File.join(Dir.getwd, 'features') @overwrite = false @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/cukehead/feature_writer.rb', line 6 def errors @errors end |
#output_path ⇒ Object
Returns the value of attribute output_path.
4 5 6 |
# File 'lib/cukehead/feature_writer.rb', line 4 def output_path @output_path end |
#overwrite ⇒ Object
Returns the value of attribute overwrite.
5 6 7 |
# File 'lib/cukehead/feature_writer.rb', line 5 def overwrite @overwrite end |
Instance Method Details
#write_features(features) ⇒ Object
Writes feature files to the location specified by :output_path.
Parameters
features
- Hash of filename => featuretext.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cukehead/feature_writer.rb', line 20 def write_features(features) FileUtils.mkdir_p(@output_path) unless File.directory? @output_path ok = true unless @overwrite features.each {|fn, text| filename = File.join(@output_path, fn) if File.exists? filename @errors << "Exists: #{filename}" ok = false end } end if ok features.each {|fn, text| filename = File.join(@output_path, fn) File.open(filename, 'w') {|f| f.write(text)} } end end |