offroad 0.0.2 → 0.0.3
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/LICENSE +674 -674
- data/README.rdoc +29 -29
- data/Rakefile +75 -75
- data/TODO +42 -42
- data/lib/app/models/offroad/group_state.rb +85 -85
- data/lib/app/models/offroad/mirror_info.rb +53 -53
- data/lib/app/models/offroad/model_state.rb +36 -36
- data/lib/app/models/offroad/received_record_state.rb +115 -115
- data/lib/app/models/offroad/sendable_record_state.rb +91 -91
- data/lib/app/models/offroad/system_state.rb +33 -33
- data/lib/cargo_streamer.rb +222 -222
- data/lib/controller_extensions.rb +74 -74
- data/lib/exceptions.rb +16 -16
- data/lib/migrate/20100512164608_create_offroad_tables.rb +72 -72
- data/lib/mirror_data.rb +376 -376
- data/lib/model_extensions.rb +378 -377
- data/lib/module_funcs.rb +94 -94
- data/lib/offroad.rb +41 -41
- data/lib/version.rb +3 -3
- data/lib/view_helper.rb +7 -7
- data/templates/offline.rb +36 -36
- data/templates/offline_database.yml +7 -7
- data/templates/offroad.yml +6 -6
- data/test/app_root/app/controllers/application_controller.rb +2 -2
- data/test/app_root/app/controllers/group_controller.rb +28 -28
- data/test/app_root/app/models/global_record.rb +10 -10
- data/test/app_root/app/models/group.rb +12 -12
- data/test/app_root/app/models/group_owned_record.rb +68 -68
- data/test/app_root/app/models/guest.rb +7 -7
- data/test/app_root/app/models/subrecord.rb +12 -12
- data/test/app_root/app/models/unmirrored_record.rb +4 -4
- data/test/app_root/app/views/group/download_down_mirror.html.erb +3 -3
- data/test/app_root/app/views/group/download_initial_down_mirror.html.erb +3 -3
- data/test/app_root/app/views/group/download_up_mirror.html.erb +5 -5
- data/test/app_root/app/views/layouts/mirror.html.erb +8 -8
- data/test/app_root/config/boot.rb +115 -115
- data/test/app_root/config/database-pg.yml +8 -8
- data/test/app_root/config/database.yml +5 -5
- data/test/app_root/config/environment.rb +24 -24
- data/test/app_root/config/environments/test.rb +17 -17
- data/test/app_root/config/offroad.yml +6 -6
- data/test/app_root/config/routes.rb +4 -4
- data/test/app_root/db/migrate/20100529235049_create_tables.rb +64 -64
- data/test/app_root/lib/common_hobo.rb +15 -15
- data/test/app_root/vendor/plugins/offroad/init.rb +2 -2
- data/test/functional/mirror_operations_test.rb +148 -148
- data/test/test_helper.rb +453 -453
- data/test/unit/app_state_tracking_test.rb +275 -275
- data/test/unit/cargo_streamer_test.rb +332 -332
- data/test/unit/global_data_test.rb +102 -102
- data/test/unit/group_controller_test.rb +152 -152
- data/test/unit/group_data_test.rb +442 -435
- data/test/unit/group_single_test.rb +136 -136
- data/test/unit/hobo_permissions_test.rb +57 -57
- data/test/unit/mirror_data_test.rb +1283 -1283
- data/test/unit/mirror_info_test.rb +31 -31
- data/test/unit/module_funcs_test.rb +37 -37
- data/test/unit/pathological_model_test.rb +62 -62
- data/test/unit/test_framework_test.rb +86 -86
- data/test/unit/unmirrored_data_test.rb +14 -14
- metadata +6 -8
data/lib/module_funcs.rb
CHANGED
@@ -1,94 +1,94 @@
|
|
1
|
-
module Offroad
|
2
|
-
@@app_online_flag = nil
|
3
|
-
@@group_base_model = nil
|
4
|
-
@@global_data_models = {}
|
5
|
-
@@group_owned_models = {}
|
6
|
-
@@group_single_models = {}
|
7
|
-
|
8
|
-
# Used in the environment configuration file to set the app to online or offline mode.
|
9
|
-
# This should not be called from within the app.
|
10
|
-
def self.config_app_online(flag)
|
11
|
-
@@app_online_flag = flag
|
12
|
-
end
|
13
|
-
|
14
|
-
# Returns true if the app is in offline mode (running on a local system without access to the main server)
|
15
|
-
def self.app_offline?
|
16
|
-
not app_online?
|
17
|
-
end
|
18
|
-
|
19
|
-
# Returns true if the app is in online mode (or in other words, this is the main server)
|
20
|
-
def self.app_online?
|
21
|
-
case @@app_online_flag
|
22
|
-
when true then true
|
23
|
-
when false then false
|
24
|
-
else raise AppModeUnknownError.new
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns a Time that identifies the version of the app
|
29
|
-
# Specifically, the modification timestamp (on the online app) of the most recently modified source file in the app
|
30
|
-
def self.app_version
|
31
|
-
# TODO Implement
|
32
|
-
# Online - When app is launched, scan all application files, returns the Time of the most recently changed file
|
33
|
-
# Offline - Based on the app version noted in the last down-mirror file successfully loaded
|
34
|
-
return 1
|
35
|
-
end
|
36
|
-
|
37
|
-
#:nodoc#
|
38
|
-
def self.init
|
39
|
-
@@config = YAML.load_file(File.join(RAILS_ROOT, "config", "offroad.yml"))
|
40
|
-
end
|
41
|
-
|
42
|
-
# Returns the record of the group base model that this app is in charge of
|
43
|
-
# This is only applicable if the app is offline
|
44
|
-
def self.offline_group
|
45
|
-
raise PluginError.new("'Offline group' is only meaningful if the app is offline") unless app_offline?
|
46
|
-
group_base_model.first
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def self.online_url
|
52
|
-
@@config[:online_url] or raise PluginError.new("No online url specified in offroad config")
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.app_name
|
56
|
-
@@config[:app_name] or raise PluginError.new("No app name specified in offroad config")
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.note_global_data_model(cls)
|
60
|
-
@@global_data_models[cls.name] = cls
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.global_data_models
|
64
|
-
@@global_data_models
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.note_group_base_model(cls)
|
68
|
-
if @@group_base_model and @@group_base_model.to_s != cls.to_s
|
69
|
-
raise ModelError.new("You can only define one group base model")
|
70
|
-
end
|
71
|
-
@@group_base_model = cls
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.group_base_model
|
75
|
-
raise ModelError.new("No group base model was specified") unless @@group_base_model
|
76
|
-
@@group_base_model
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.note_group_owned_model(cls)
|
80
|
-
@@group_owned_models[cls.name] = cls
|
81
|
-
end
|
82
|
-
|
83
|
-
def self.group_owned_models
|
84
|
-
@@group_owned_models
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.note_group_single_model(cls)
|
88
|
-
@@group_single_models[cls.name] = cls
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.group_single_models
|
92
|
-
@@group_single_models
|
93
|
-
end
|
94
|
-
end
|
1
|
+
module Offroad
|
2
|
+
@@app_online_flag = nil
|
3
|
+
@@group_base_model = nil
|
4
|
+
@@global_data_models = {}
|
5
|
+
@@group_owned_models = {}
|
6
|
+
@@group_single_models = {}
|
7
|
+
|
8
|
+
# Used in the environment configuration file to set the app to online or offline mode.
|
9
|
+
# This should not be called from within the app.
|
10
|
+
def self.config_app_online(flag)
|
11
|
+
@@app_online_flag = flag
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns true if the app is in offline mode (running on a local system without access to the main server)
|
15
|
+
def self.app_offline?
|
16
|
+
not app_online?
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns true if the app is in online mode (or in other words, this is the main server)
|
20
|
+
def self.app_online?
|
21
|
+
case @@app_online_flag
|
22
|
+
when true then true
|
23
|
+
when false then false
|
24
|
+
else raise AppModeUnknownError.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns a Time that identifies the version of the app
|
29
|
+
# Specifically, the modification timestamp (on the online app) of the most recently modified source file in the app
|
30
|
+
def self.app_version
|
31
|
+
# TODO Implement
|
32
|
+
# Online - When app is launched, scan all application files, returns the Time of the most recently changed file
|
33
|
+
# Offline - Based on the app version noted in the last down-mirror file successfully loaded
|
34
|
+
return 1
|
35
|
+
end
|
36
|
+
|
37
|
+
#:nodoc#
|
38
|
+
def self.init
|
39
|
+
@@config = YAML.load_file(File.join(RAILS_ROOT, "config", "offroad.yml"))
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns the record of the group base model that this app is in charge of
|
43
|
+
# This is only applicable if the app is offline
|
44
|
+
def self.offline_group
|
45
|
+
raise PluginError.new("'Offline group' is only meaningful if the app is offline") unless app_offline?
|
46
|
+
group_base_model.first
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def self.online_url
|
52
|
+
@@config[:online_url] or raise PluginError.new("No online url specified in offroad config")
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.app_name
|
56
|
+
@@config[:app_name] or raise PluginError.new("No app name specified in offroad config")
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.note_global_data_model(cls)
|
60
|
+
@@global_data_models[cls.name] = cls
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.global_data_models
|
64
|
+
@@global_data_models
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.note_group_base_model(cls)
|
68
|
+
if @@group_base_model and @@group_base_model.to_s != cls.to_s
|
69
|
+
raise ModelError.new("You can only define one group base model")
|
70
|
+
end
|
71
|
+
@@group_base_model = cls
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.group_base_model
|
75
|
+
raise ModelError.new("No group base model was specified") unless @@group_base_model
|
76
|
+
@@group_base_model
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.note_group_owned_model(cls)
|
80
|
+
@@group_owned_models[cls.name] = cls
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.group_owned_models
|
84
|
+
@@group_owned_models
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.note_group_single_model(cls)
|
88
|
+
@@group_single_models[cls.name] = cls
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.group_single_models
|
92
|
+
@@group_single_models
|
93
|
+
end
|
94
|
+
end
|
data/lib/offroad.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
# Offroad
|
2
|
-
|
3
|
-
require 'version'
|
4
|
-
require 'module_funcs'
|
5
|
-
require 'cargo_streamer'
|
6
|
-
require 'exceptions'
|
7
|
-
require 'mirror_data'
|
8
|
-
|
9
|
-
path = File.join(File.dirname(__FILE__), 'app', 'models')
|
10
|
-
$LOAD_PATH << path
|
11
|
-
ActiveSupport::Dependencies.autoload_paths << path
|
12
|
-
|
13
|
-
require 'ar-extensions' # External dependency
|
14
|
-
# Monkey patch a bug in ar-extensions which breaks postgres compatibility
|
15
|
-
module ActiveRecord # :nodoc:
|
16
|
-
module ConnectionAdapters # :nodoc:
|
17
|
-
class AbstractAdapter # :nodoc:
|
18
|
-
def next_value_for_sequence(sequence_name)
|
19
|
-
%{nextval('#{sequence_name}')}
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
require 'controller_extensions'
|
27
|
-
class ActionController::Base
|
28
|
-
extend Offroad::ControllerExtensions
|
29
|
-
end
|
30
|
-
|
31
|
-
require 'model_extensions'
|
32
|
-
class ActiveRecord::Base
|
33
|
-
extend Offroad::ModelExtensions
|
34
|
-
end
|
35
|
-
|
36
|
-
require 'view_helper'
|
37
|
-
class ActionView::Base
|
38
|
-
include Offroad::ViewHelper
|
39
|
-
end
|
40
|
-
|
41
|
-
Offroad::init
|
1
|
+
# Offroad
|
2
|
+
|
3
|
+
require 'version'
|
4
|
+
require 'module_funcs'
|
5
|
+
require 'cargo_streamer'
|
6
|
+
require 'exceptions'
|
7
|
+
require 'mirror_data'
|
8
|
+
|
9
|
+
path = File.join(File.dirname(__FILE__), 'app', 'models')
|
10
|
+
$LOAD_PATH << path
|
11
|
+
ActiveSupport::Dependencies.autoload_paths << path
|
12
|
+
|
13
|
+
require 'ar-extensions' # External dependency
|
14
|
+
# Monkey patch a bug in ar-extensions which breaks postgres compatibility
|
15
|
+
module ActiveRecord # :nodoc:
|
16
|
+
module ConnectionAdapters # :nodoc:
|
17
|
+
class AbstractAdapter # :nodoc:
|
18
|
+
def next_value_for_sequence(sequence_name)
|
19
|
+
%{nextval('#{sequence_name}')}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
require 'controller_extensions'
|
27
|
+
class ActionController::Base
|
28
|
+
extend Offroad::ControllerExtensions
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'model_extensions'
|
32
|
+
class ActiveRecord::Base
|
33
|
+
extend Offroad::ModelExtensions
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'view_helper'
|
37
|
+
class ActionView::Base
|
38
|
+
include Offroad::ViewHelper
|
39
|
+
end
|
40
|
+
|
41
|
+
Offroad::init
|
data/lib/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Offroad
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
1
|
+
module Offroad
|
2
|
+
VERSION = "0.0.3"
|
3
|
+
end
|
data/lib/view_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
module Offroad
|
2
|
-
module ViewHelper
|
3
|
-
def link_to_online_app(name = nil)
|
4
|
-
link_to(name ? name : Offroad::online_url, Offroad::online_url)
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
1
|
+
module Offroad
|
2
|
+
module ViewHelper
|
3
|
+
def link_to_online_app(name = nil)
|
4
|
+
link_to(name ? name : Offroad::online_url, Offroad::online_url)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
data/templates/offline.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
# This file defines the offline envrionment
|
2
|
-
# "Offline" means that the application is running on a local network, with only a subset of the real online app's data
|
3
|
-
# It is implemented by the gem Offroad
|
4
|
-
|
5
|
-
# Settings specified here will take precedence over those in config/environment.rb
|
6
|
-
|
7
|
-
# Use the offline database configuration file instead of the regular one
|
8
|
-
config.database_configuration_file = "config/offline_database.yml"
|
9
|
-
|
10
|
-
# Code is not reloaded between requests
|
11
|
-
config.cache_classes = true
|
12
|
-
|
13
|
-
# Full error reports are disabled and caching is turned on
|
14
|
-
config.action_controller.consider_all_requests_local = false
|
15
|
-
config.action_controller.perform_caching = true
|
16
|
-
config.action_view.cache_template_loading = true
|
17
|
-
|
18
|
-
# See everything in the log (default is :info)
|
19
|
-
# config.log_level = :debug
|
20
|
-
|
21
|
-
# Use a different logger for distributed setups
|
22
|
-
# config.logger = SyslogLogger.new
|
23
|
-
|
24
|
-
# Use a different cache store in production
|
25
|
-
# config.cache_store = :mem_cache_store
|
26
|
-
|
27
|
-
# Enable serving of images, stylesheets, and javascripts from an asset server
|
28
|
-
# config.action_controller.asset_host = "http://assets.example.com"
|
29
|
-
|
30
|
-
# Disable delivery errors, bad email addresses will be ignored
|
31
|
-
# config.action_mailer.raise_delivery_errors = false
|
32
|
-
|
33
|
-
# Enable threaded mode
|
34
|
-
# config.threadsafe!
|
35
|
-
|
36
|
-
Offroad::config_app_online(false)
|
1
|
+
# This file defines the offline envrionment
|
2
|
+
# "Offline" means that the application is running on a local network, with only a subset of the real online app's data
|
3
|
+
# It is implemented by the gem Offroad
|
4
|
+
|
5
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
6
|
+
|
7
|
+
# Use the offline database configuration file instead of the regular one
|
8
|
+
config.database_configuration_file = "config/offline_database.yml"
|
9
|
+
|
10
|
+
# Code is not reloaded between requests
|
11
|
+
config.cache_classes = true
|
12
|
+
|
13
|
+
# Full error reports are disabled and caching is turned on
|
14
|
+
config.action_controller.consider_all_requests_local = false
|
15
|
+
config.action_controller.perform_caching = true
|
16
|
+
config.action_view.cache_template_loading = true
|
17
|
+
|
18
|
+
# See everything in the log (default is :info)
|
19
|
+
# config.log_level = :debug
|
20
|
+
|
21
|
+
# Use a different logger for distributed setups
|
22
|
+
# config.logger = SyslogLogger.new
|
23
|
+
|
24
|
+
# Use a different cache store in production
|
25
|
+
# config.cache_store = :mem_cache_store
|
26
|
+
|
27
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
28
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
29
|
+
|
30
|
+
# Disable delivery errors, bad email addresses will be ignored
|
31
|
+
# config.action_mailer.raise_delivery_errors = false
|
32
|
+
|
33
|
+
# Enable threaded mode
|
34
|
+
# config.threadsafe!
|
35
|
+
|
36
|
+
Offroad::config_app_online(false)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# This database config file is used by the 'offline' environment
|
2
|
-
|
3
|
-
offline:
|
4
|
-
adapter: sqlite3
|
5
|
-
database: db/offline.sqlite3
|
6
|
-
pool: 5
|
7
|
-
timeout: 5000
|
1
|
+
# This database config file is used by the 'offline' environment
|
2
|
+
|
3
|
+
offline:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/offline.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
data/templates/offroad.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Configuration for Offroad
|
2
|
-
# :online_url: The URL for the regular online version of the app
|
3
|
-
# :app_name: The name of the application, to be used in helpful messages in the generated mirror data files.
|
4
|
-
|
5
|
-
:online_url: "http://example.com"
|
6
|
-
:app_name: Example Application
|
1
|
+
# Configuration for Offroad
|
2
|
+
# :online_url: The URL for the regular online version of the app
|
3
|
+
# :app_name: The name of the application, to be used in helpful messages in the generated mirror data files.
|
4
|
+
|
5
|
+
:online_url: "http://example.com"
|
6
|
+
:app_name: Example Application
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class ApplicationController < ActionController::Base
|
2
|
-
end
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
class GroupController < ApplicationController
|
2
|
-
offroad_group_controller
|
3
|
-
|
4
|
-
def download_down_mirror
|
5
|
-
render_down_mirror_file Group.find(params[:id]), "down-mirror-file", :layout => "mirror"
|
6
|
-
end
|
7
|
-
|
8
|
-
def download_initial_down_mirror
|
9
|
-
render_down_mirror_file Group.find(params[:id]), "down-mirror-file", :layout => "mirror", :initial_mode => true
|
10
|
-
end
|
11
|
-
|
12
|
-
def download_up_mirror
|
13
|
-
render_up_mirror_file Group.find(params[:id]), "up-mirror-file", :layout => "mirror"
|
14
|
-
end
|
15
|
-
|
16
|
-
def upload_up_mirror
|
17
|
-
load_up_mirror_file Group.find(params[:id]), params[:mirror_data]
|
18
|
-
end
|
19
|
-
|
20
|
-
def upload_down_mirror
|
21
|
-
load_down_mirror_file Group.find(params[:id]), params[:mirror_data]
|
22
|
-
end
|
23
|
-
|
24
|
-
def upload_initial_down_mirror
|
25
|
-
load_down_mirror_file nil, params[:mirror_data], :initial_mode => true
|
26
|
-
render :upload_down_mirror
|
27
|
-
end
|
28
|
-
end
|
1
|
+
class GroupController < ApplicationController
|
2
|
+
offroad_group_controller
|
3
|
+
|
4
|
+
def download_down_mirror
|
5
|
+
render_down_mirror_file Group.find(params[:id]), "down-mirror-file", :layout => "mirror"
|
6
|
+
end
|
7
|
+
|
8
|
+
def download_initial_down_mirror
|
9
|
+
render_down_mirror_file Group.find(params[:id]), "down-mirror-file", :layout => "mirror", :initial_mode => true
|
10
|
+
end
|
11
|
+
|
12
|
+
def download_up_mirror
|
13
|
+
render_up_mirror_file Group.find(params[:id]), "up-mirror-file", :layout => "mirror"
|
14
|
+
end
|
15
|
+
|
16
|
+
def upload_up_mirror
|
17
|
+
load_up_mirror_file Group.find(params[:id]), params[:mirror_data]
|
18
|
+
end
|
19
|
+
|
20
|
+
def upload_down_mirror
|
21
|
+
load_down_mirror_file Group.find(params[:id]), params[:mirror_data]
|
22
|
+
end
|
23
|
+
|
24
|
+
def upload_initial_down_mirror
|
25
|
+
load_down_mirror_file nil, params[:mirror_data], :initial_mode => true
|
26
|
+
render :upload_down_mirror
|
27
|
+
end
|
28
|
+
end
|