Class: SchemaDev::Readme
- Inherits:
-
Object
- Object
- SchemaDev::Readme
- Defined in:
- lib/schema_dev/readme.rb
Instance Attribute Summary collapse
-
#matrix ⇒ Object
Returns the value of attribute matrix.
-
#readme ⇒ Object
Returns the value of attribute readme.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(matrix) ⇒ Readme
constructor
A new instance of Readme.
- #sub_matrix(lines) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(matrix) ⇒ Readme
Returns a new instance of Readme.
11 12 13 14 |
# File 'lib/schema_dev/readme.rb', line 11 def initialize(matrix) self.matrix = matrix self.readme = Pathname.new('README.md') end |
Instance Attribute Details
#matrix ⇒ Object
Returns the value of attribute matrix.
9 10 11 |
# File 'lib/schema_dev/readme.rb', line 9 def matrix @matrix end |
#readme ⇒ Object
Returns the value of attribute readme.
9 10 11 |
# File 'lib/schema_dev/readme.rb', line 9 def readme @readme end |
Class Method Details
.update(config) ⇒ Object
5 6 7 |
# File 'lib/schema_dev/readme.rb', line 5 def self.update(config) new(config.matrix).update end |
Instance Method Details
#sub_matrix(lines) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/schema_dev/readme.rb', line 26 def sub_matrix(lines) pattern = %r{^\s*<!-- SCHEMA_DEV: MATRIX} before = lines.take_while(&it !~ pattern) return lines if before == lines after = lines.reverse.take_while(&it !~ pattern).reverse contents = [] contents << "<!-- SCHEMA_DEV: MATRIX - begin -->\n" contents << "<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->\n" self.matrix.group_by(&it.slice(:ruby, :rails)).each do |pair, items| contents << "* ruby **#{pair[:ruby]}** with rails **#{pair[:rails]}**, using #{items.map{|item| "**#{item[:db]}**"}.to_sentence(last_word_connector: ' or ')}\n" end contents << "<!-- SCHEMA_DEV: MATRIX - end -->\n" before + contents + after end |
#update ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/schema_dev/readme.rb', line 16 def update return false unless readme.exist? lines = readme.readlines newlines = sub_matrix(lines) if lines != newlines readme.write newlines.join return true end end |