Class: Migrant::Boxes
- Inherits:
-
Object
- Object
- Migrant::Boxes
- Defined in:
- lib/migrant/boxes.rb
Overview
Loads and persists information about the boxes managed by this migrant configuration
Instance Method Summary collapse
- #[](environment) ⇒ Object
- #[]=(environment, box) ⇒ Object
- #add(environment, provider, id) ⇒ Object
-
#initialize(path) ⇒ Boxes
constructor
A new instance of Boxes.
-
#load ⇒ Object
Returns an Boxes instance.
- #remove(environment) ⇒ Object
- #save ⇒ Object
Constructor Details
Instance Method Details
#[](environment) ⇒ Object
39 40 41 42 |
# File 'lib/migrant/boxes.rb', line 39 def [](environment) environment = 'default' if environment.nil? @boxes['boxes'][environment] end |
#[]=(environment, box) ⇒ Object
44 45 46 47 |
# File 'lib/migrant/boxes.rb', line 44 def []=(environment,box) environment = 'default' if environment.nil? @boxes['boxes'][environment] = box end |
#add(environment, provider, id) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/migrant/boxes.rb', line 49 def add(environment,provider,id) environment = 'default' if environment.nil? box = Box.new(provider,id) self[environment] = box self end |
#load ⇒ Object
Returns an Boxes instance
20 21 22 23 |
# File 'lib/migrant/boxes.rb', line 20 def load @boxes = YAML.load(File.read(@path)) if File.exists?(@path) self end |
#remove(environment) ⇒ Object
56 57 58 59 60 |
# File 'lib/migrant/boxes.rb', line 56 def remove(environment) environment = 'default' if environment.nil? @boxes['boxes'].delete(environment) self end |
#save ⇒ Object
33 34 35 36 37 |
# File 'lib/migrant/boxes.rb', line 33 def save() File.open(@path,'w') do |f| f.write(YAML.dump(@boxes)) end end |