class SchemaEvolutionManager::MigrationFile
Represents a single file to make a schema migration, typically stored in the scripts subdirectory.
Constants
- DEFAULTS
Attributes
attribute_values[R]
path[R]
Public Class Methods
new(path)
click to toggle source
# File lib/schema-evolution-manager/migration_file.rb, line 49 def initialize(path) @path = path Preconditions.check_state(File.exist?(@path), "File[#{@path}] does not exist") @attribute_values = parse_attribute_values end
Private Instance Methods
each_property() { |name, value| ... }
click to toggle source
Parse properties from the comments. Looks for this pattern:
– sem.attribute.name = value
and yields each matching row with |name, value|
# File lib/schema-evolution-manager/migration_file.rb, line 80 def each_property IO.readlines(path).each do |l| begin stripped = l.strip.encode("UTF-8") if stripped.match(/^\-\-\s+sem\.attribute\./) stripped.sub!(/^\-\-\s+sem\.attribute\./, '') name, value = stripped.split(/\=/, 2).map(&:strip) yield name, value end rescue Encoding::InvalidByteSequenceError # Ignore - attributes must be in ascii end end rescue Encoding::InvalidByteSequenceError # Ignore - file must be in ascii in order to parse attributes end
parse_attribute_values()
click to toggle source
Returns a list of AttributeValues from the file itself, including all defaults set by SEM. AttributeValues are defined in comments in the file.
# File lib/schema-evolution-manager/migration_file.rb, line 60 def parse_attribute_values values = [] each_property do |name, value| values << AttributeValue.new(name, value) end DEFAULTS.each do |default| if values.find { |v| v.attribute.name == default.attribute.name }.nil? values << default end end values end