Class: Rake::Migrations::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/migrations/manifest.rb

Constant Summary collapse

DEFAULT_FILE_PATH =
Rails.root.join('.rake.migrations.yml')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Manifest

Returns a new instance of Manifest.



13
14
15
16
# File 'lib/rake/migrations/manifest.rb', line 13

def initialize(file_path)
  @file_path = file_path
  @tasks     = []
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



11
12
13
# File 'lib/rake/migrations/manifest.rb', line 11

def file_path
  @file_path
end

#tasksObject (readonly)

Returns the value of attribute tasks.



11
12
13
# File 'lib/rake/migrations/manifest.rb', line 11

def tasks
  @tasks
end

Class Method Details

.load(file_path = DEFAULT_FILE_PATH) ⇒ Object



5
6
7
8
9
# File 'lib/rake/migrations/manifest.rb', line 5

def self.load(file_path = DEFAULT_FILE_PATH)
  manifest = new(file_path)
  manifest.load
  manifest
end

Instance Method Details

#add_task(task) ⇒ Object



18
19
20
# File 'lib/rake/migrations/manifest.rb', line 18

def add_task(task)
  @tasks << task unless @tasks.include?(task)
end

#loadObject



26
27
28
29
30
31
32
# File 'lib/rake/migrations/manifest.rb', line 26

def load
  manifest = YAML.load_file(file_path).with_indifferent_access
  (manifest[:tasks] || []).each do |task|
    add_task Rake::Migrations::Task.new(*task)
  end
rescue Errno::ENOENT
end

#saveObject



34
35
36
# File 'lib/rake/migrations/manifest.rb', line 34

def save
  File.open(file_path, 'w') { |f| f.write to_yaml  }
end

#to_hObject Also known as: to_hash



38
39
40
41
42
# File 'lib/rake/migrations/manifest.rb', line 38

def to_h
  {
    tasks: tasks.map(&:name)
  }
end

#to_yamlObject



45
46
47
# File 'lib/rake/migrations/manifest.rb', line 45

def to_yaml
  to_hash.to_yaml
end

#update(task) ⇒ Object



22
23
24
# File 'lib/rake/migrations/manifest.rb', line 22

def update(task)
  add_task(task) && save
end