Class: Rake::Migrations::Manifest
- Inherits:
-
Object
- Object
- Rake::Migrations::Manifest
- Defined in:
- lib/rake/migrations/manifest.rb
Constant Summary collapse
- DEFAULT_FILE_PATH =
Rails.root.join('.rake.migrations.yml')
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Class Method Summary collapse
Instance Method Summary collapse
- #add_task(task) ⇒ Object
-
#initialize(file_path) ⇒ Manifest
constructor
A new instance of Manifest.
- #load ⇒ Object
- #save ⇒ Object
- #to_h ⇒ Object (also: #to_hash)
- #to_yaml ⇒ Object
- #update(task) ⇒ Object
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_path ⇒ Object (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 |
#tasks ⇒ Object (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 |
#load ⇒ Object
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 |
#save ⇒ Object
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_h ⇒ Object 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_yaml ⇒ Object
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 |