Class: Rake::Migrations::Configuration

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

Constant Summary collapse

DEFAULT_FILE_PATH =
Rails.root.join('config', 'tasks.yml')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Configuration

Returns a new instance of Configuration.



13
14
15
16
# File 'lib/rake/migrations/configuration.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/configuration.rb', line 11

def file_path
  @file_path
end

#tasksObject (readonly)

Returns the value of attribute tasks.



11
12
13
# File 'lib/rake/migrations/configuration.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/configuration.rb', line 5

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

Instance Method Details

#add_task(task) ⇒ Object



25
26
27
# File 'lib/rake/migrations/configuration.rb', line 25

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

#loadObject



18
19
20
21
22
23
# File 'lib/rake/migrations/configuration.rb', line 18

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