lev 0.0.1 → 0.0.2
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/.gitignore +8 -0
- data/Gemfile.lock +1 -1
- data/lib/lev.rb +2 -0
- data/lib/lev/exceptions.rb +2 -1
- data/lib/lev/handle_with.rb +12 -8
- data/lib/lev/handler.rb +22 -10
- data/lib/lev/routine_nesting.rb +1 -1
- data/lib/lev/version.rb +1 -1
- metadata +5 -4
data/.gitignore
ADDED
data/Gemfile.lock
CHANGED
data/lib/lev.rb
CHANGED
@@ -46,9 +46,11 @@ module Lev
|
|
46
46
|
class Configuration
|
47
47
|
# This HTML class is added to form fields that caused errors
|
48
48
|
attr_accessor :form_error_class
|
49
|
+
attr_accessor :security_transgression_error
|
49
50
|
|
50
51
|
def initialize
|
51
52
|
@form_error_class = 'error'
|
53
|
+
@security_transgression_error = Lev::SecurityTransgression
|
52
54
|
super
|
53
55
|
end
|
54
56
|
end
|
data/lib/lev/exceptions.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
class IsolationMismatch < StandardError; end
|
1
|
+
class Lev::IsolationMismatch < StandardError; end
|
2
|
+
class Lev::SecurityTransgression < StandardError; end
|
data/lib/lev/handle_with.rb
CHANGED
@@ -29,18 +29,22 @@ module Lev
|
|
29
29
|
#
|
30
30
|
module HandleWith
|
31
31
|
def handle_with(handler, options)
|
32
|
-
options
|
33
|
-
options
|
34
|
-
options
|
32
|
+
success_action = options.delete(:success) || lambda {}
|
33
|
+
failure_action = options.delete(:failure) || lambda {}
|
34
|
+
complete_action = options.delete(:complete) || lambda {}
|
35
35
|
|
36
|
-
|
36
|
+
options[:params] ||= params
|
37
|
+
options[:request] ||= request
|
38
|
+
options[:caller] ||= current_user
|
37
39
|
|
38
|
-
|
40
|
+
@results, @errors = handler.handle(options)
|
41
|
+
|
42
|
+
if complete_action.nil?
|
39
43
|
@errors.empty? ?
|
40
|
-
|
41
|
-
|
44
|
+
success_action.call :
|
45
|
+
failure_action.call
|
42
46
|
else
|
43
|
-
|
47
|
+
complete_action.call
|
44
48
|
end
|
45
49
|
end
|
46
50
|
end
|
data/lib/lev/handler.rb
CHANGED
@@ -64,8 +64,14 @@ module Lev
|
|
64
64
|
# See the documentation for Lev::RoutineNesting about other requirements and
|
65
65
|
# capabilities of handler classes.
|
66
66
|
#
|
67
|
-
# The handle methods take
|
68
|
-
#
|
67
|
+
# The handle methods take a hash of arguments.
|
68
|
+
# caller: the calling user
|
69
|
+
# params: the params object
|
70
|
+
# request: the http request object
|
71
|
+
#
|
72
|
+
# These arguments are optional or required depending on the implementation of
|
73
|
+
# the specific handler, i.e. if a handler wants to use the 'caller' method, it
|
74
|
+
# must have been supplied to the handle method.
|
69
75
|
#
|
70
76
|
# Example:
|
71
77
|
#
|
@@ -89,15 +95,17 @@ module Lev
|
|
89
95
|
end
|
90
96
|
end
|
91
97
|
|
92
|
-
def
|
98
|
+
def handle(options={})
|
93
99
|
in_transaction do
|
94
|
-
handle_guts(
|
100
|
+
handle_guts(options)
|
95
101
|
end
|
96
102
|
end
|
97
103
|
|
104
|
+
alias_method :call, :handle
|
105
|
+
|
98
106
|
module ClassMethods
|
99
|
-
def handle(
|
100
|
-
new.
|
107
|
+
def handle(options={})
|
108
|
+
new.handle(options)
|
101
109
|
end
|
102
110
|
|
103
111
|
def paramify(group, options={}, &block)
|
@@ -155,17 +163,21 @@ module Lev
|
|
155
163
|
protected
|
156
164
|
|
157
165
|
attr_accessor :params
|
166
|
+
attr_accessor :request
|
167
|
+
attr_accessor :options
|
158
168
|
attr_accessor :caller
|
159
169
|
attr_accessor :results
|
160
170
|
|
161
|
-
def handle_guts(
|
162
|
-
self.params = params
|
163
|
-
self.
|
171
|
+
def handle_guts(options)
|
172
|
+
self.params = options.delete(:params)
|
173
|
+
self.request = options.delete(:request)
|
174
|
+
self.caller = options.delete(:caller)
|
175
|
+
self.options = options
|
164
176
|
self.errors = Errors.new
|
165
177
|
self.results = {}
|
166
178
|
|
167
179
|
setup
|
168
|
-
raise
|
180
|
+
raise Lev.configuration.security_transgression_error unless authorized?
|
169
181
|
validate_paramified_params
|
170
182
|
exec unless errors?
|
171
183
|
|
data/lib/lev/routine_nesting.rb
CHANGED
@@ -72,7 +72,7 @@ module Lev
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def in_transaction(options={})
|
75
|
-
if self
|
75
|
+
if self != topmost_runner || self.class.transaction_isolation == TransactionIsolation.no_transaction
|
76
76
|
yield
|
77
77
|
else
|
78
78
|
ActiveRecord::Base.isolation_level( self.class.transaction_isolation.symbol ) do
|
data/lib/lev/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: transaction_isolation
|
@@ -98,6 +98,7 @@ executables: []
|
|
98
98
|
extensions: []
|
99
99
|
extra_rdoc_files: []
|
100
100
|
files:
|
101
|
+
- .gitignore
|
101
102
|
- .ruby-gemset
|
102
103
|
- .ruby-version
|
103
104
|
- Gemfile
|
@@ -139,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
140
|
version: '0'
|
140
141
|
segments:
|
141
142
|
- 0
|
142
|
-
hash: -
|
143
|
+
hash: -199634686570320863
|
143
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
145
|
none: false
|
145
146
|
requirements:
|
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
149
|
version: '0'
|
149
150
|
segments:
|
150
151
|
- 0
|
151
|
-
hash: -
|
152
|
+
hash: -199634686570320863
|
152
153
|
requirements: []
|
153
154
|
rubyforge_project:
|
154
155
|
rubygems_version: 1.8.25
|