redcar 0.11.0dev → 0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +14 -1
- data/README.md +28 -8
- data/Rakefile +23 -18
- data/bin/redcar +9 -4
- data/lib/redcar.rb +42 -4
- data/lib/redcar/installer.rb +7 -2
- data/lib/redcar/logger.rb +64 -0
- data/lib/redcar/runner.rb +17 -8
- data/lib/redcar/usage.rb +2 -0
- data/plugins/application/features/step_definitions/tree_steps.rb +4 -4
- data/plugins/application/features/support/env.rb +6 -6
- data/plugins/application/lib/application.rb +31 -3
- data/plugins/application/lib/application/command.rb +6 -0
- data/plugins/application/lib/application/command/executor.rb +0 -1
- data/plugins/application/lib/application/commands/application_commands.rb +21 -0
- data/plugins/application/lib/application/commands/notebook_commands.rb +73 -0
- data/plugins/application/lib/application/commands/tab_commands.rb +105 -0
- data/plugins/application/lib/application/commands/treebook_commands.rb +117 -0
- data/plugins/application/lib/application/commands/window_commands.rb +68 -0
- data/plugins/{tree/lib → application/lib/application}/tree.rb +0 -4
- data/plugins/{tree/lib → application/lib/application}/tree/command.rb +0 -0
- data/plugins/{tree/lib → application/lib/application}/tree/controller.rb +0 -0
- data/plugins/{tree/lib → application/lib/application}/tree/mirror.rb +0 -0
- data/plugins/application/spec/application/keymap/builder_spec.rb +1 -1
- data/plugins/application/spec/application/menu/builder_spec.rb +2 -2
- data/plugins/application_swt/lib/application_swt.rb +4 -2
- data/plugins/application_swt/lib/swt/vtab_label.rb +6 -3
- data/plugins/auto_indenter/lib/auto_indenter/document_controller.rb +6 -3
- data/plugins/clojure/lib/clojure.rb +2 -2
- data/plugins/core/lib/core.rb +0 -4
- data/plugins/core/lib/core/gui.rb +2 -4
- data/plugins/core/lib/core/plugin/storage.rb +68 -21
- data/plugins/core/spec/core/base_storage_spec.rb +81 -0
- data/plugins/core/spec/core/shared_storage_spec.rb +49 -0
- data/plugins/core/spec/core/storage_spec.rb +13 -63
- data/plugins/declarations/lib/declarations.rb +3 -1
- data/plugins/document_search/features/replace.feature +29 -20
- data/plugins/document_search/lib/document_search/find_speedbar.rb +4 -1
- data/plugins/edit_view/features/indentation_commands.feature +6 -5
- data/plugins/edit_view/features/step_definitions/notebook_steps.rb +4 -4
- data/plugins/edit_view/features/step_definitions/tab_steps.rb +7 -7
- data/plugins/edit_view/features/step_definitions/window_steps.rb +2 -2
- data/plugins/edit_view/lib/edit_view.rb +15 -1
- data/plugins/edit_view/lib/edit_view/modified_tabs_checker.rb +7 -7
- data/plugins/edit_view_swt/lib/edit_view_swt.rb +7 -6
- data/plugins/execute_current_tab/lib/execute_current_tab.rb +1 -1
- data/plugins/groovy/lib/groovy.rb +3 -3
- data/plugins/groovy/lib/groovy/commands.rb +1 -1
- data/plugins/help/lib/help/view_controller.rb +5 -0
- data/plugins/help/views/index.html.erb +10 -1
- data/plugins/html_view/features/step_definitions/html_view_steps.rb +1 -1
- data/plugins/html_view/features/support/env.rb +0 -15
- data/plugins/html_view/lib/html_view.rb +3 -4
- data/plugins/html_view/lib/html_view/commands.rb +1 -1
- data/plugins/key_bindings/lib/key_bindings.rb +34 -0
- data/plugins/key_bindings/plugin.rb +8 -0
- data/plugins/{tree → key_bindings}/spec/spec_helper.rb +0 -0
- data/plugins/line_tools/features/lower_text.feature +3 -4
- data/plugins/line_tools/lib/line_tools.rb +6 -5
- data/plugins/mirah/lib/mirah.rb +2 -2
- data/plugins/pair_highlighter/lib/pair_highlighter/document_controller.rb +5 -3
- data/plugins/project/features/open_directory_tree.feature +1 -1
- data/plugins/project/features/step_definitions/file_steps.rb +5 -5
- data/plugins/project/features/step_definitions/find_file_steps.rb +2 -3
- data/plugins/project/features/support/env.rb +4 -0
- data/plugins/project/lib/project.rb +15 -9
- data/plugins/project/lib/project/commands.rb +46 -16
- data/plugins/project/lib/project/dir_controller.rb +1 -1
- data/plugins/project/lib/project/dir_mirror.rb +3 -2
- data/plugins/project/lib/project/drb_service.rb +3 -1
- data/plugins/project/lib/project/file_list.rb +99 -21
- data/plugins/project/lib/project/find_file_dialog.rb +8 -24
- data/plugins/project/lib/project/manager.rb +68 -12
- data/plugins/project/lib/project/project_tree_controller.rb +1 -1
- data/plugins/project/plugin.rb +1 -2
- data/plugins/project_search/features/word_search.feature +1 -1
- data/plugins/project_search/lib/project_search.rb +16 -6
- data/plugins/project_search/lib/project_search/commands.rb +15 -28
- data/plugins/project_search/lib/project_search/hit.rb +4 -0
- data/plugins/project_search/lib/project_search/lucene_index.rb +14 -4
- data/plugins/project_search/lib/project_search/views/_file.html.erb +11 -11
- data/plugins/project_search/lib/project_search/word_search.rb +22 -4
- data/plugins/project_search/spec/project_search/word_search_spec.rb +2 -2
- data/plugins/redcar/redcar.rb +140 -588
- data/plugins/repl/features/step_definitions/repl_steps.rb +3 -3
- data/plugins/repl/features/support/fake_repl.rb +1 -1
- data/plugins/ruby/lib/ruby.rb +4 -4
- data/plugins/runnables/features/fixtures/alternate.ruby +1 -0
- data/plugins/runnables/features/fixtures/line_app.rb +1 -0
- data/plugins/runnables/features/fixtures/name_app.rb +1 -0
- data/plugins/runnables/features/fixtures/params_app.rb +1 -0
- data/plugins/runnables/features/fixtures/runnable_app.rb +1 -0
- data/plugins/runnables/lib/runnables.rb +21 -0
- data/plugins/runnables/lib/runnables/command_output_controller.rb +14 -9
- data/plugins/runnables/lib/runnables/output_processor.rb +4 -4
- data/plugins/runnables/lib/runnables/running_process_checker.rb +6 -6
- data/plugins/runnables/plugin.rb +1 -2
- data/plugins/scm/lib/scm.rb +18 -18
- data/plugins/scm/lib/scm/commit_mirror.rb +2 -2
- data/plugins/scm/lib/scm/scm_changes_controller.rb +1 -1
- data/plugins/scm_hg/lib/scm_hg.rb +1 -1
- data/plugins/snippets/lib/snippets/document_controller.rb +46 -40
- data/plugins/swt/lib/swt.rb +2 -0
- data/plugins/test_runner/lib/test_runner.rb +1 -0
- data/plugins/test_runner/lib/test_runner/jasmine_test_runner.rb +15 -0
- data/plugins/test_runner/lib/test_runner/runnable_test_runner.rb +21 -5
- data/plugins/textmate/lib/textmate.rb +5 -1
- data/plugins/textmate/lib/textmate/preference.rb +4 -0
- data/plugins/textmate/lib/textmate/snippet.rb +0 -2
- data/plugins/textmate/lib/textmate/tree_mirror.rb +6 -5
- data/plugins/textmate/plugin.rb +1 -1
- data/plugins/textmate/vendor/redcar-bundles/Bundles/C.tmbundle/Syntaxes/C.plist +2 -2
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Clojure.tmbundle/info.plist +2 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Cucumber.tmbundle/Syntaxes/Cucumber_Plain_Text_Feature.tmLanguage +0 -4
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Cucumber.tmbundle/info.plist +2 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Mirah.tmbundle/info.plist +3 -1
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Palm-WebOS-Development.tmbundle/info.plist +2 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/RedcarRepl.tmbundle/info.plist +2 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/SQL.tmbundle/info.plist +2 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Scala.tmbundle/info.plist +2 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Smalltalk.tmbundle/Preferences/GNU_Smalltalk.tmPreferences +1 -1
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Smalltalk.tmbundle/Preferences/MIST_Smalltalk_Format.tmPreferences +1 -1
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Smalltalk.tmbundle/info.plist +2 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Vala.tmbundle/info.plist +4 -2
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Webrat.tmbundle/info.plist +2 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/YAML.tmbundle/Syntaxes/YAML.plist +1 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/groovy.tmbundle/info.plist +2 -0
- data/plugins/textmate/vendor/redcar-bundles/Themes/Twilight.tmTheme +0 -2
- data/plugins/todo_list/lib/todo_list.rb +3 -3
- data/plugins/todo_list/lib/todo_list/todo_controller.rb +1 -1
- data/plugins/web_bookmarks/features/step_definitions/web_steps.rb +1 -1
- data/plugins/web_bookmarks/lib/web_bookmarks.rb +11 -4
- data/plugins/web_bookmarks/lib/web_bookmarks/commands.rb +1 -1
- data/plugins/web_bookmarks/plugin.rb +1 -2
- metadata +29 -20
- data/plugins/core/lib/core/logger.rb +0 -28
- data/plugins/file_parser/lib/file_parser.rb +0 -125
- data/plugins/file_parser/plugin.rb +0 -7
- data/plugins/tree/plugin.rb +0 -9
@@ -0,0 +1,68 @@
|
|
1
|
+
module Redcar
|
2
|
+
class Application
|
3
|
+
class OpenNewWindowCommand < Command
|
4
|
+
|
5
|
+
def initialize(title=nil)
|
6
|
+
@title = title
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute
|
10
|
+
window = Redcar.app.new_window
|
11
|
+
window.title = @title if @title
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class FocusWindowCommand < Command
|
16
|
+
def initialize(window=nil)
|
17
|
+
@window = window
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute
|
21
|
+
win.focus
|
22
|
+
@window = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def win
|
26
|
+
@window || super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class CloseWindowCommand < Command
|
31
|
+
def initialize(window=nil)
|
32
|
+
@window = window
|
33
|
+
end
|
34
|
+
|
35
|
+
def execute
|
36
|
+
Redcar.app.call_on_plugins(:close_window_guard, win) do |guard|
|
37
|
+
return unless guard
|
38
|
+
end
|
39
|
+
win.close
|
40
|
+
quit_if_no_windows if [:linux, :windows].include?(Redcar.platform)
|
41
|
+
@window = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def quit_if_no_windows
|
47
|
+
if Redcar.app.windows.length == 0
|
48
|
+
if Application.storage['stay_resident_after_last_window_closed'] && !(ARGV.include?("--multiple-instance"))
|
49
|
+
puts 'continuing to run to wait for incoming drb connections later'
|
50
|
+
else
|
51
|
+
QuitCommand.new.run
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def win
|
57
|
+
@window || super
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class ToggleFullscreen < Command
|
62
|
+
def execute
|
63
|
+
Redcar.app.focussed_window.fullscreen = !Redcar.app.focussed_window.fullscreen
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -9,7 +9,7 @@ describe "Redcar::Keymap::Builder DSL" do
|
|
9
9
|
|
10
10
|
it "add entries to the keymap" do
|
11
11
|
builder = Redcar::Keymap::Builder.new("test", :osx) do
|
12
|
-
link "Ctrl+S", :
|
12
|
+
link "Ctrl+S", :OpenNewEditTabCommand
|
13
13
|
end
|
14
14
|
builder.keymap.length.should == 1
|
15
15
|
builder.keymap.command("Ctrl+S")
|
@@ -9,12 +9,12 @@ describe "Redcar::Menu::Builder DSL" do
|
|
9
9
|
|
10
10
|
it "adds entries to the menu" do
|
11
11
|
builder = Redcar::Menu::Builder.new do
|
12
|
-
item "New", :
|
12
|
+
item "New", :OpenNewEditTabCommand
|
13
13
|
end
|
14
14
|
builder.menu.length.should == 1
|
15
15
|
item = builder.menu.entries.first
|
16
16
|
item.text.should == "New"
|
17
|
-
item.command.should == :
|
17
|
+
item.command.should == :OpenNewEditTabCommand
|
18
18
|
end
|
19
19
|
|
20
20
|
it "adds separators to the menu" do
|
@@ -31,6 +31,8 @@ require "application_swt-#{Redcar::VERSION}"
|
|
31
31
|
module Redcar
|
32
32
|
class ApplicationSWT
|
33
33
|
include Redcar::Controller
|
34
|
+
|
35
|
+
attr_reader :fake_shell
|
34
36
|
|
35
37
|
def self.display
|
36
38
|
@display ||= Swt.display
|
@@ -143,7 +145,7 @@ module Redcar
|
|
143
145
|
end
|
144
146
|
|
145
147
|
def refresh_menu
|
146
|
-
if Redcar.platform == :osx
|
148
|
+
if Redcar.platform == :osx and @fake_shell
|
147
149
|
old_menu_bar = @fake_shell.menu_bar
|
148
150
|
fake_menu_controller = ApplicationSWT::Menu.new(FakeWindow.new(@fake_shell), Redcar.app.main_menu, Redcar.app.main_keymap, Swt::SWT::BAR)
|
149
151
|
fake_shell.menu_bar = fake_menu_controller.menu_bar
|
@@ -152,7 +154,7 @@ module Redcar
|
|
152
154
|
end
|
153
155
|
|
154
156
|
def refresh_toolbar
|
155
|
-
if Redcar.platform == :osx
|
157
|
+
if Redcar.platform == :osx and @fake_shell
|
156
158
|
fake_toolbar_controller = ApplicationSWT::ToolBar.new(FakeWindow.new(@fake_shell), Redcar.app.main_toolbar, Swt::SWT::FLAT)
|
157
159
|
end
|
158
160
|
end
|
@@ -9,9 +9,12 @@ module Swt
|
|
9
9
|
include Swt::Events::MouseListener
|
10
10
|
include Swt::Events::MouseTrackListener
|
11
11
|
|
12
|
-
CLOSE_ICON = Redcar::ApplicationSWT::Icon.swt_image(:close)
|
13
12
|
ICON_PADDING = 3
|
14
13
|
|
14
|
+
def close_icon
|
15
|
+
@@close_icon ||= Redcar::ApplicationSWT::Icon.swt_image(:close)
|
16
|
+
end
|
17
|
+
|
15
18
|
def initialize(tab, parent, style)
|
16
19
|
@label = Swt::Widgets::Label.new(parent, style)
|
17
20
|
@active = false
|
@@ -98,7 +101,7 @@ module Swt
|
|
98
101
|
end
|
99
102
|
|
100
103
|
def mouseUp(e)
|
101
|
-
if show_close and
|
104
|
+
if show_close and close_icon.bounds.contains(e.x - ICON_PADDING, e.y - ICON_PADDING)
|
102
105
|
@tab.parent.remove_item(@tab)
|
103
106
|
else
|
104
107
|
activate if e.button == 1
|
@@ -106,7 +109,7 @@ module Swt
|
|
106
109
|
end
|
107
110
|
|
108
111
|
def mouseEnter(e)
|
109
|
-
@icon =
|
112
|
+
@icon = close_icon
|
110
113
|
redraw
|
111
114
|
end
|
112
115
|
|
@@ -57,9 +57,12 @@ module Redcar
|
|
57
57
|
if get_flags(line, rules) != @flags
|
58
58
|
edit_view = document.edit_view
|
59
59
|
analyzer = Analyzer.new(rules, document, edit_view.tab_width, edit_view.soft_tabs?)
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
new_indentation = analyzer.calculate_for_line(start_line_ix, true)
|
61
|
+
if new_indentation >= 0
|
62
|
+
increase_ignore
|
63
|
+
document.indentation.set_level(start_line_ix, new_indentation)
|
64
|
+
decrease_ignore
|
65
|
+
end
|
63
66
|
end
|
64
67
|
end
|
65
68
|
end
|
@@ -8,7 +8,7 @@ module Redcar
|
|
8
8
|
Menu::Builder.build do
|
9
9
|
sub_menu "Plugins" do
|
10
10
|
sub_menu "REPL" do
|
11
|
-
item "Open Clojure REPL",
|
11
|
+
item "Open Clojure REPL", OpenClojureREPL
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -24,7 +24,7 @@ module Redcar
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
class
|
27
|
+
class OpenClojureREPL < Redcar::REPL::OpenREPL
|
28
28
|
def execute
|
29
29
|
open_repl(ReplMirror.new)
|
30
30
|
end
|
data/plugins/core/lib/core.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
-
require "core/logger"
|
5
4
|
require "core/reentry_helpers"
|
6
5
|
require "core/controller"
|
7
6
|
require "core/gui"
|
@@ -32,10 +31,7 @@ module Redcar
|
|
32
31
|
end
|
33
32
|
|
34
33
|
class Core
|
35
|
-
include HasLogger
|
36
|
-
|
37
34
|
def self.loaded
|
38
|
-
Core::Logger.init
|
39
35
|
unless File.exist?(Redcar.user_dir)
|
40
36
|
FileUtils.mkdir(Redcar.user_dir)
|
41
37
|
end
|
@@ -8,8 +8,6 @@ module Redcar
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
include Redcar::Core::HasLogger
|
12
|
-
|
13
11
|
attr_reader :name
|
14
12
|
|
15
13
|
# Initialize a new named gui.
|
@@ -32,10 +30,10 @@ module Redcar
|
|
32
30
|
# Starts the event loop for this gui.
|
33
31
|
def start
|
34
32
|
if ARGV.include?("--quit-immediately")
|
35
|
-
|
33
|
+
Redcar.log.info("Quitting straight away")
|
36
34
|
exit
|
37
35
|
else
|
38
|
-
|
36
|
+
Redcar.log.info("Starting event loop")
|
39
37
|
@event_loop.start
|
40
38
|
end
|
41
39
|
end
|
@@ -1,30 +1,28 @@
|
|
1
1
|
|
2
2
|
module Redcar
|
3
3
|
class Plugin
|
4
|
-
class
|
5
|
-
|
6
|
-
attr_writer :storage_dir
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.storage_dir
|
10
|
-
@user_dir ||= File.join(Redcar.user_dir, "storage")
|
11
|
-
end
|
12
|
-
|
4
|
+
class BaseStorage
|
5
|
+
|
13
6
|
# Open a storage file or create it if it doesn't exist.
|
14
7
|
#
|
15
|
-
# @param [String]
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
# @param [String] storage_dir the path to the directory the storage file should exist in
|
9
|
+
# @param [String] name a (short) name, should be suitable for use as a filename
|
10
|
+
def initialize(storage_dir, name)
|
11
|
+
@storage_dir = storage_dir
|
12
|
+
@name = name
|
13
|
+
@mutex = Mutex.new
|
14
|
+
unless File.exists?(@storage_dir)
|
15
|
+
FileUtils.mkdir_p(@storage_dir)
|
20
16
|
end
|
21
17
|
rollback
|
22
18
|
end
|
23
19
|
|
24
20
|
# Save the storage to disk.
|
25
21
|
def save
|
26
|
-
|
27
|
-
|
22
|
+
@mutex.synchronize do
|
23
|
+
File.open(path, "w") { |f| YAML.dump(@storage, f) }
|
24
|
+
update_timestamp
|
25
|
+
end
|
28
26
|
self
|
29
27
|
end
|
30
28
|
|
@@ -32,9 +30,11 @@ module Redcar
|
|
32
30
|
# it hasn't been saved.
|
33
31
|
def rollback
|
34
32
|
if File.exists?(path)
|
35
|
-
@
|
36
|
-
|
37
|
-
|
33
|
+
@mutex.synchronize do
|
34
|
+
@storage = YAML.load_file(path)
|
35
|
+
raise 'storage file is corrupted--please delete ' + path unless @storage.is_a?(Hash)
|
36
|
+
update_timestamp
|
37
|
+
end
|
38
38
|
else
|
39
39
|
@storage = {}
|
40
40
|
end
|
@@ -60,6 +60,7 @@ module Redcar
|
|
60
60
|
value
|
61
61
|
end
|
62
62
|
|
63
|
+
# Set a default value for a key and save it to disk
|
63
64
|
def set_default(key, value)
|
64
65
|
unless @storage.has_key?(key)
|
65
66
|
self[key] = value
|
@@ -67,6 +68,8 @@ module Redcar
|
|
67
68
|
value
|
68
69
|
end
|
69
70
|
|
71
|
+
# Get all keys in the storage
|
72
|
+
# @return [Array] the Array with all keys
|
70
73
|
def keys
|
71
74
|
@storage.keys
|
72
75
|
end
|
@@ -74,11 +77,55 @@ module Redcar
|
|
74
77
|
private
|
75
78
|
|
76
79
|
def path
|
77
|
-
File.join(
|
80
|
+
File.join(@storage_dir, @name + ".yaml")
|
78
81
|
end
|
79
82
|
|
80
83
|
def update_timestamp
|
81
|
-
@last_modified_time = File.stat(path
|
84
|
+
@last_modified_time = File.stat(path).mtime
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class Storage < Plugin::BaseStorage
|
89
|
+
def self.storage_dir=(value)
|
90
|
+
@user_dir = value
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.storage_dir
|
94
|
+
@user_dir ||= File.join(Redcar.user_dir, "storage")
|
95
|
+
end
|
96
|
+
|
97
|
+
def initialize(name)
|
98
|
+
super(self.class.storage_dir, name)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# A Storage which is used by multiple plugins. This kind of storage can only
|
103
|
+
# contain arrays, because otherwise plugins could not set their defaults as
|
104
|
+
# addition to the existing ones of other plugins.
|
105
|
+
class SharedStorage < Plugin::Storage
|
106
|
+
# Set a default value for a key or update it, if it already exists
|
107
|
+
def set_or_update_default(key, value)
|
108
|
+
if @storage.has_key?(key)
|
109
|
+
update_default(key, value)
|
110
|
+
else
|
111
|
+
if value.instance_of? Array
|
112
|
+
set_default(key, value)
|
113
|
+
else
|
114
|
+
set_default(key, [value])
|
115
|
+
end
|
116
|
+
end
|
117
|
+
@storage[key] = @storage[key].uniq
|
118
|
+
value
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def update_default(key, value)
|
124
|
+
if value.instance_of? Array
|
125
|
+
self[key] = self[key] + value
|
126
|
+
else
|
127
|
+
self[key] << value
|
128
|
+
end
|
82
129
|
end
|
83
130
|
end
|
84
131
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
3
|
+
|
4
|
+
describe Redcar::Plugin::BaseStorage do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@tmp_dir = File.join(File.dirname(__FILE__), "tmp")
|
8
|
+
FileUtils.mkdir_p(@tmp_dir)
|
9
|
+
end
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
FileUtils.rm_rf(@tmp_dir)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_new_storage
|
16
|
+
Redcar::Plugin::BaseStorage.new(@tmp_dir, 'test_storage_saved')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "acts like a hash" do
|
20
|
+
storage = get_new_storage
|
21
|
+
storage[:some_key] = "some value"
|
22
|
+
storage[:some_key].should == "some value"
|
23
|
+
storage[:some_key] = "some other value"
|
24
|
+
storage[:some_key].should == "some other value"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "saves to disk" do
|
28
|
+
storage = get_new_storage
|
29
|
+
storage[:some_key] = "some value"
|
30
|
+
storage = get_new_storage
|
31
|
+
storage[:some_key].should == "some value"
|
32
|
+
|
33
|
+
FileUtils.rm_rf(storage.send(:path))
|
34
|
+
storage = get_new_storage
|
35
|
+
storage[:some_key].should be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has a set default method" do
|
39
|
+
storage = get_new_storage
|
40
|
+
storage.set_default('a', 'b')
|
41
|
+
storage['a'].should == 'b'
|
42
|
+
storage = get_new_storage
|
43
|
+
storage['a'].should == 'b'
|
44
|
+
storage['a'] = 'c'
|
45
|
+
storage['a'].should == 'c'
|
46
|
+
storage = get_new_storage
|
47
|
+
storage['a'].should == 'c'
|
48
|
+
storage['b'] = false
|
49
|
+
storage.set_default('b', true)
|
50
|
+
storage['b'].should == false
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should raise an error when the storage file is invalid/corrupt" do
|
54
|
+
storage = get_new_storage
|
55
|
+
FileUtils.touch(storage.send(:path))
|
56
|
+
lambda { storage.rollback }.should raise_error(RuntimeError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should reload when the storage file itself has been elsewise modified" do
|
60
|
+
storage = get_new_storage
|
61
|
+
storage['a'] = 'b'
|
62
|
+
storage['a'].should == 'b'
|
63
|
+
storage['a'].should == 'b'
|
64
|
+
sleep 1 # windows doesn't have finer granularity than this
|
65
|
+
File.open(storage.send(:path), 'w') do |f|
|
66
|
+
f.write "---
|
67
|
+
a: new"
|
68
|
+
end
|
69
|
+
storage['a'].should == 'new'
|
70
|
+
storage['a'].should == 'new'
|
71
|
+
storage = get_new_storage
|
72
|
+
storage['a'].should == 'new'
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should allow per-instance storage directory" do
|
76
|
+
storage = Redcar::Plugin::BaseStorage.new(@tmp_dir, 'test_storage_saved')
|
77
|
+
storage2 = Redcar::Plugin::BaseStorage.new(File.join(@tmp_dir, "sub"), 'test_storage_saved')
|
78
|
+
storage.send(:path).should_not == storage2.send(:path)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|