lev 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
7
+ spec/dummy/.sass-cache
8
+ .DS_Store
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lev (0.0.1)
4
+ lev (0.0.2)
5
5
  active_attr
6
6
  transaction_isolation
7
7
  transaction_retry
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
@@ -1 +1,2 @@
1
- class IsolationMismatch < StandardError; end
1
+ class Lev::IsolationMismatch < StandardError; end
2
+ class Lev::SecurityTransgression < StandardError; end
@@ -29,18 +29,22 @@ module Lev
29
29
  #
30
30
  module HandleWith
31
31
  def handle_with(handler, options)
32
- options[:success] ||= lambda {}
33
- options[:failure] ||= lambda {}
34
- options[:params] ||= params
32
+ success_action = options.delete(:success) || lambda {}
33
+ failure_action = options.delete(:failure) || lambda {}
34
+ complete_action = options.delete(:complete) || lambda {}
35
35
 
36
- @results, @errors = handler.handle(current_user, options[:params])
36
+ options[:params] ||= params
37
+ options[:request] ||= request
38
+ options[:caller] ||= current_user
37
39
 
38
- if options[:complete].nil?
40
+ @results, @errors = handler.handle(options)
41
+
42
+ if complete_action.nil?
39
43
  @errors.empty? ?
40
- options[:success].call :
41
- options[:failure].call
44
+ success_action.call :
45
+ failure_action.call
42
46
  else
43
- options[:complete].call
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 the caller and the params objects, which should be
68
- # self-explanatory.
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 call(caller, params, options={})
98
+ def handle(options={})
93
99
  in_transaction do
94
- handle_guts(caller, params)
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(caller, params, options={})
100
- new.call(caller, params, options)
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(caller, params)
162
- self.params = params
163
- self.caller = caller
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 SecurityTransgression unless authorized?
180
+ raise Lev.configuration.security_transgression_error unless authorized?
169
181
  validate_paramified_params
170
182
  exec unless errors?
171
183
 
@@ -72,7 +72,7 @@ module Lev
72
72
  end
73
73
 
74
74
  def in_transaction(options={})
75
- if self == topmost_runner || self.class.transaction_isolation == TransactionIsolation.no_transaction
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
@@ -1,3 +1,3 @@
1
1
  module Lev
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-17 00:00:00.000000000 Z
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: -115681344003179955
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: -115681344003179955
152
+ hash: -199634686570320863
152
153
  requirements: []
153
154
  rubyforge_project:
154
155
  rubygems_version: 1.8.25