RubyApp 0.0.22 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/ruby_app/element.rb +12 -6
- data/lib/ruby_app/elements/base/base_page.js.haml +2 -2
- data/lib/ruby_app/elements/pages/test_pages/exception_test_page.rb +1 -1
- data/lib/ruby_app/exceptions/base/base_exception.rb +21 -0
- data/lib/ruby_app/exceptions/session_invalid_exception.rb +19 -0
- data/lib/ruby_app/log.rb +3 -1
- data/lib/ruby_app/rack/route.rb +16 -8
- data/lib/ruby_app/session.rb +11 -5
- data/lib/ruby_app/translations/en.yml +3 -0
- data/lib/ruby_app/version.rb +1 -1
- metadata +6 -4
data/Gemfile.lock
CHANGED
data/lib/ruby_app/element.rb
CHANGED
@@ -26,9 +26,14 @@ module RubyApp
|
|
26
26
|
|
27
27
|
attr_reader :now, :source
|
28
28
|
|
29
|
-
def initialize(data)
|
30
|
-
|
31
|
-
|
29
|
+
def initialize(data = nil)
|
30
|
+
if data
|
31
|
+
@now = Time.parse(data['now'])
|
32
|
+
@source = RubyApp::Element.get_element(data['source_id'])
|
33
|
+
else
|
34
|
+
@now = Time.now
|
35
|
+
@source = nil
|
36
|
+
end
|
32
37
|
@statements = []
|
33
38
|
end
|
34
39
|
|
@@ -83,7 +88,8 @@ module RubyApp
|
|
83
88
|
def to_hash
|
84
89
|
{
|
85
90
|
'_class' => self.class.to_s,
|
86
|
-
'
|
91
|
+
'now' => @now,
|
92
|
+
'source_id' => @source ? @source.element_id : nil,
|
87
93
|
'statements' => @statements
|
88
94
|
}
|
89
95
|
end
|
@@ -96,8 +102,8 @@ module RubyApp
|
|
96
102
|
|
97
103
|
class ExceptionEvent < RubyApp::Element::Event
|
98
104
|
|
99
|
-
def initialize(
|
100
|
-
super(
|
105
|
+
def initialize(exception)
|
106
|
+
super()
|
101
107
|
self.alert(exception.message)
|
102
108
|
end
|
103
109
|
|
@@ -6,12 +6,12 @@
|
|
6
6
|
this.interval = #{self.interval * 1000};
|
7
7
|
this._interval = 0;
|
8
8
|
this.sendEvent = function(event) {
|
9
|
+
event.session_id = '#{RubyApp::Session.session_id}';
|
9
10
|
event.now = new Date().toString();
|
10
11
|
response = $.post(location.href, event);
|
11
12
|
response
|
12
13
|
.success( function(event) {
|
13
14
|
$.each(event.statements, function(index, statement) {
|
14
|
-
// alert(statement);
|
15
15
|
eval(statement);
|
16
16
|
} );
|
17
17
|
} )
|
@@ -99,7 +99,7 @@
|
|
99
99
|
if ( RubyApp.interval > 0 ) {
|
100
100
|
window.clearInterval(RubyApp._interval);
|
101
101
|
}
|
102
|
-
RubyApp.sendEvent({_class:'RubyApp::Elements::Page::UnloadedEvent', source_id:$('html').attr('id')});
|
102
|
+
// RubyApp.sendEvent({_class:'RubyApp::Elements::Page::UnloadedEvent', source_id:$('html').attr('id')});
|
103
103
|
});
|
104
104
|
|
105
105
|
= yield
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RubyApp
|
2
|
+
|
3
|
+
module Exceptions
|
4
|
+
|
5
|
+
module Base
|
6
|
+
require 'ruby_app/mixins/translate_mixin'
|
7
|
+
|
8
|
+
class BaseException < Exception
|
9
|
+
extend RubyApp::Mixins::TranslateMixin
|
10
|
+
|
11
|
+
def initialize(message)
|
12
|
+
super(message)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RubyApp
|
2
|
+
|
3
|
+
module Exceptions
|
4
|
+
require 'ruby_app/exceptions/base/base_exception'
|
5
|
+
|
6
|
+
class SessionInvalidException < RubyApp::Exceptions::Base::BaseException
|
7
|
+
|
8
|
+
attr_reader :session_id
|
9
|
+
|
10
|
+
def initialize(session_id)
|
11
|
+
super(RubyApp::Exceptions::SessionInvalidException.translate.message)
|
12
|
+
@session_id = session_id
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/ruby_app/log.rb
CHANGED
@@ -11,7 +11,9 @@ module RubyApp
|
|
11
11
|
self.error('-' * 80)
|
12
12
|
self.error("exception=#{exception.class.inspect} #{exception.message}")
|
13
13
|
self.error('-' * 80)
|
14
|
-
|
14
|
+
exception.backtrace.each do |line|
|
15
|
+
self.error(line)
|
16
|
+
end
|
15
17
|
self.error('-' * 80)
|
16
18
|
end
|
17
19
|
|
data/lib/ruby_app/rack/route.rb
CHANGED
@@ -11,9 +11,11 @@ module RubyApp
|
|
11
11
|
require 'ruby_app/elements/exception_element'
|
12
12
|
require 'ruby_app/elements/pages/exception_page'
|
13
13
|
require 'ruby_app/elements/pages/quit_page'
|
14
|
+
require 'ruby_app/exceptions/session_invalid_exception'
|
14
15
|
require 'ruby_app/log'
|
15
16
|
require 'ruby_app/mixins/route_mixin'
|
16
17
|
require 'ruby_app/request'
|
18
|
+
require 'ruby_app/session'
|
17
19
|
|
18
20
|
class Route
|
19
21
|
extend RubyApp::Mixins::RouteMixin
|
@@ -83,20 +85,26 @@ module RubyApp
|
|
83
85
|
|
84
86
|
route(RubyApp::Mixins::RouteMixin::POST, /.*/) do |method, path|
|
85
87
|
RubyApp::Log.debug("#{self}.post(...) method=#{method.inspect} path=#{path.inspect} POST=#{RubyApp::Request.POST.inspect}")
|
88
|
+
RubyApp::Log.debug("#{self}.post(...) RubyApp::Session.session_id=#{RubyApp::Session.session_id}")
|
86
89
|
begin
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
if RubyApp::Session.session_id == RubyApp::Request.POST['session_id']
|
91
|
+
event = RubyApp::Element::Event.from_hash(RubyApp::Request.POST)
|
92
|
+
event.process!
|
93
|
+
[
|
94
|
+
200,
|
95
|
+
{ 'content-type' => 'application/json' },
|
96
|
+
[ Yajl::Encoder.new.encode(event.to_hash) ]
|
97
|
+
]
|
98
|
+
else
|
99
|
+
raise RubyApp::Exceptions::SessionInvalidException.new(RubyApp::Request.POST['session_id'])
|
100
|
+
end
|
101
|
+
|
94
102
|
rescue Exception => exception
|
95
103
|
RubyApp::Log.exception(exception)
|
96
104
|
[
|
97
105
|
200,
|
98
106
|
{ 'content-type' => 'application/json' },
|
99
|
-
[ Yajl::Encoder.new.encode(RubyApp::Element::ExceptionEvent.new(
|
107
|
+
[ Yajl::Encoder.new.encode(RubyApp::Element::ExceptionEvent.new(exception).to_hash) ]
|
100
108
|
]
|
101
109
|
end
|
102
110
|
end
|
data/lib/ruby_app/session.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module RubyApp
|
2
2
|
require 'ruby_app/application'
|
3
|
+
require 'ruby_app/log'
|
3
4
|
require 'ruby_app/mixins/configure_mixin'
|
4
5
|
require 'ruby_app/mixins/delegate_mixin'
|
5
6
|
require 'ruby_app/mixins/translate_mixin'
|
@@ -21,15 +22,19 @@ module RubyApp
|
|
21
22
|
|
22
23
|
end
|
23
24
|
|
24
|
-
attr_reader :pages
|
25
|
+
attr_reader :session_id, :pages
|
25
26
|
attr_accessor :identity, :data
|
26
27
|
|
27
|
-
def initialize(page = nil)
|
28
|
-
|
29
|
-
@pages = [
|
28
|
+
def initialize(session_id, page = nil)
|
29
|
+
@session_id = session_id
|
30
|
+
@pages = []
|
30
31
|
@dialogs = []
|
31
32
|
@identity = nil
|
32
33
|
@data = {}
|
34
|
+
|
35
|
+
require 'ruby_app/elements/pages/default_page'
|
36
|
+
@pages.push(page || RubyApp::Elements::Pages::DefaultPage.new)
|
37
|
+
|
33
38
|
end
|
34
39
|
|
35
40
|
def [](key)
|
@@ -70,7 +75,8 @@ module RubyApp
|
|
70
75
|
end
|
71
76
|
|
72
77
|
def self.create!
|
73
|
-
|
78
|
+
RubyApp::Request.session[:_initialize] = true
|
79
|
+
Thread.current[:_session] = RubyApp::Request.session[:_session] ||= RubyApp::Application.options.session_class.new(RubyApp::Request.env['rack.session.options'] ? RubyApp::Request.env['rack.session.options'][:id] : nil)
|
74
80
|
if block_given?
|
75
81
|
begin
|
76
82
|
yield
|
data/lib/ruby_app/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RubyApp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 49
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 23
|
10
|
+
version: 0.0.23
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Frank G. Ficnar
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-12-
|
18
|
+
date: 2011-12-11 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -498,6 +498,8 @@ files:
|
|
498
498
|
- lib/ruby_app/elements/pages/test_pages/test_page.html.haml
|
499
499
|
- lib/ruby_app/elements/pages/test_pages/test_page.js.haml
|
500
500
|
- lib/ruby_app/elements/pages/test_pages/test_page.rb
|
501
|
+
- lib/ruby_app/exceptions/base/base_exception.rb
|
502
|
+
- lib/ruby_app/exceptions/session_invalid_exception.rb
|
501
503
|
- lib/ruby_app/language.rb
|
502
504
|
- lib/ruby_app/log.rb
|
503
505
|
- lib/ruby_app/mixins/configure_mixin.rb
|