Module: XMigra::DeclarativeMigration

Defined in:
lib/xmigra/declarative_migration.rb

Defined Under Namespace

Modules: ChainSupport Classes: MissingImplementationError, QuestionableImplementationError

Constant Summary collapse

VALID_GOALS =
%w{creation adoption revision renunciation destruction}
GOAL_KEY =
'does'
TARGET_KEY =
'of object'
DECLARATION_VERSION_KEY =
'to realize'
QUALIFICATION_KEY =
'implementation qualification'
SUBDIR =
'declarative'
Missing =
Class.new do
  def goal
    :newly_managed_object
  end
  
  def declarative_status
    :unimplemented
  end
  
  def delta(file_path)
    Pathname(file_path).readlines.map {|l| '+' + l}.join('')
  end
end.new

Instance Method Summary collapse

Instance Method Details

#affected_objectObject



106
107
108
# File 'lib/xmigra/declarative_migration.rb', line 106

def affected_object
  @declarative_target ||= @all_info[TARGET_KEY].dup.freeze
end

#changesObject

Override the way the base class handles changes – this integrates with the “history” command



112
113
114
115
116
117
118
# File 'lib/xmigra/declarative_migration.rb', line 112

def changes
  if management_migration?
    []
  else
    [affected_object]
  end
end

#declarative_file_pathObject



142
143
144
# File 'lib/xmigra/declarative_migration.rb', line 142

def declarative_file_path
  @declarative_file_path ||= Pathname(file_path).dirname.join(SUBDIR, affected_object + '.yaml')
end

#declarative_statusObject



146
147
148
149
150
# File 'lib/xmigra/declarative_migration.rb', line 146

def declarative_status
  @declarative_status ||= begin
    vcs_comparator(:expected_content_method=>:implementation_of?).relative_version(declarative_file_path)
  end
end

#delta(file_path) ⇒ Object



152
153
154
# File 'lib/xmigra/declarative_migration.rb', line 152

def delta(file_path)
  vcs_changes_from(vcs_latest_revision, file_path)
end

#goalObject



100
101
102
103
104
# File 'lib/xmigra/declarative_migration.rb', line 100

def goal
  @declarative_goal ||= @all_info[GOAL_KEY].tap do |val|
    raise(ArgumentError, "'#{GOAL_KEY}' must be one of: #{VALID_GOALS.join(', ')}") unless VALID_GOALS.include?(val)
  end.to_sym
end

#implementation_of?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/xmigra/declarative_migration.rb', line 138

def implementation_of?(file_path)
  XMigra.secure_digest(file_path.read) == implemented_version
end

#implemented_versionObject

This method is only used when the declarative file has uncommitted modifications and the migration file is uncommitted



134
135
136
# File 'lib/xmigra/declarative_migration.rb', line 134

def implemented_version
  @declarative_implemented_ver ||= (@all_info[DECLARATION_VERSION_KEY].dup.freeze if vcs_uncommitted?)
end

#management_migration?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/xmigra/declarative_migration.rb', line 128

def management_migration?
  [:adoption, :renunciation].include? goal
end

#questionable?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/xmigra/declarative_migration.rb', line 156

def questionable?
  @all_info.has_key? QUALIFICATION_KEY
end

#sqlObject



120
121
122
123
124
125
126
# File 'lib/xmigra/declarative_migration.rb', line 120

def sql
  if management_migration?
    ''
  else
    super()
  end
end