Class: CIAgainst::TravisYML
- Inherits:
-
Object
- Object
- CIAgainst::TravisYML
- Defined in:
- lib/ci_against/travis_yml.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #code ⇒ Object
-
#initialize(yaml_string) ⇒ TravisYML
constructor
A new instance of TravisYML.
- #insert_line(line, lineno) ⇒ Object
- #replace_line(line, lineno) ⇒ Object
Constructor Details
#initialize(yaml_string) ⇒ TravisYML
Returns a new instance of TravisYML.
3 4 5 6 7 8 |
# File 'lib/ci_against/travis_yml.rb', line 3 def initialize(yaml_string) @nleol = yaml_string[-1] == "\n" @tree = parse(yaml_string) @lines = yaml_string.lines(chomp: true) @line_offest = @lines.map{0} << 0 end |
Instance Attribute Details
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
10 11 12 |
# File 'lib/ci_against/travis_yml.rb', line 10 def lines @lines end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
10 11 12 |
# File 'lib/ci_against/travis_yml.rb', line 10 def tree @tree end |
Instance Method Details
#code ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ci_against/travis_yml.rb', line 22 def code res = @lines.join("\n") if @nleol res << "\n" end res end |
#insert_line(line, lineno) ⇒ Object
12 13 14 15 16 |
# File 'lib/ci_against/travis_yml.rb', line 12 def insert_line(line, lineno) offset = @line_offest[0..lineno].sum @lines = [*lines[0...(lineno+offset)], line, *lines[(lineno+offset)..-1]] @line_offest[lineno] += 1 end |
#replace_line(line, lineno) ⇒ Object
18 19 20 |
# File 'lib/ci_against/travis_yml.rb', line 18 def replace_line(line, lineno) @lines[lineno] = line end |