Class: ElasticGraph::SchemaDefinition::SchemaArtifact
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaDefinition::SchemaArtifact
- Defined in:
- lib/elastic_graph/schema_definition/schema_artifact_manager.rb
Instance Method Summary collapse
- #diff(color:) ⇒ Object
- #dump(output) ⇒ Object
- #existing_dumped_contents ⇒ Object
- #out_of_date? ⇒ Boolean
Instance Method Details
#diff(color:) ⇒ Object
448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/elastic_graph/schema_definition/schema_artifact_manager.rb', line 448 def diff(color:) return nil unless exists? ::Tempfile.create do |f| f.write(dumped_contents.chomp) f.fsync `git diff --no-index #{file_name} #{f.path}#{" --color" if color}` .gsub(file_name, "existing_contents") .gsub(f.path, "/updated_contents") end end |
#dump(output) ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/elastic_graph/schema_definition/schema_artifact_manager.rb', line 424 def dump(output) if out_of_date? dirname = File.dirname(file_name) FileUtils.mkdir_p(dirname) # Create directory if needed. ::File.write(file_name, dumped_contents) output.puts "Dumped schema artifact to `#{file_name}`." else output.puts "`#{file_name}` is already up to date." end end |
#existing_dumped_contents ⇒ Object
440 441 442 443 444 445 446 |
# File 'lib/elastic_graph/schema_definition/schema_artifact_manager.rb', line 440 def existing_dumped_contents return nil unless exists? # We drop the first 2 lines because it is the comment block containing dynamic elements. file_contents = ::File.read(file_name).split("\n").drop(2).join("\n") loader.call(file_contents) end |
#out_of_date? ⇒ Boolean
436 437 438 |
# File 'lib/elastic_graph/schema_definition/schema_artifact_manager.rb', line 436 def out_of_date? (_ = existing_dumped_contents) != desired_contents end |