Skip to content

Commit

Permalink
use a different way of setting up defaults, remove old method
Browse files Browse the repository at this point in the history
  • Loading branch information
rdp committed Feb 15, 2010
1 parent a8cfcdd commit 54d0b6b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
9 changes: 7 additions & 2 deletions plugins/application/lib/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def window_closed(window)
@window_handlers.delete(window)
if windows.length == 0 and [:linux, :windows].include?(Redcar.platform)
# default to exit now
if Application.storage.get_with_default('stay_resident_after_last_window_closed', 'no') == 'yes'
if Application.storage['stay_resident_after_last_window_closed'] == 'yes'
puts 'continuing to run to wait for incoming drb connections later'
else
quit
Expand All @@ -129,7 +129,12 @@ def window_closed(window)
end

def self.storage
@storage ||= Plugin::Storage.new('application_plugin')
@storage ||= begin
@storage = Plugin::Storage.new('application_plugin')
# setup some defaults
@storage['stay_resident_after_last_window_closed'] ||= 'no'
@storage
end
end

# All Redcar::Notebooks in all Windows.
Expand Down
12 changes: 0 additions & 12 deletions plugins/core/lib/core/plugin/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ def keys
@storage.keys
end

# gets a value or a default (and assigns the default, if it has never been set)
# like value = (storage[key] ||= default)
def get_with_default(key, value)
if @storage[key]
@storage[key]
else
@storage[key] = value
save
value
end
end

private

def path
Expand Down
8 changes: 0 additions & 8 deletions plugins/core/spec/core/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,4 @@
FileUtils.rm_rf(storage.send(:path))
end

it "has a get_with_default method" do
storage = Redcar::Plugin::Storage.new('test_storage_saved2')
storage.get_with_default("a", "b").should == "b"
storage['a'] = 'c'
storage.get_with_default("a", "b").should == "c"

FileUtils.rm_rf(storage.send(:path))
end
end

0 comments on commit 54d0b6b

Please sign in to comment.