lev 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ module Lev
2
+ module Utilities
3
+
4
+ def self.deep_merge(hash, override_hash)
5
+ result = hash.dup
6
+ override_hash.each_pair do |k,v|
7
+ tv = result[k]
8
+ result[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? deep_merge(tv, v) : v
9
+ end
10
+ result
11
+ end
12
+
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Lev
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe CreateSprocket do
4
+
5
+ it "should transfer errors appropriately" do
6
+ results, errors = CreateSprocket.call(1,"42")
7
+ end
8
+
9
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lev::Utilities do
4
+
5
+ it "should merge properly" do
6
+ default_options = {
7
+ translations: {
8
+ outputs: {
9
+ scope: :blah
10
+ }
11
+ }
12
+ }
13
+
14
+ options = {
15
+ translations: {
16
+ inputs: {
17
+ type: :verbatim
18
+ },
19
+ outputs: {
20
+ map: {foo: :bar}
21
+ }
22
+ }
23
+ }
24
+
25
+ expected = {
26
+ translations: {
27
+ outputs: {
28
+ scope: :blah,
29
+ map: {foo: :bar}
30
+ },
31
+ inputs: {
32
+ type: :verbatim
33
+ }
34
+ }
35
+ }
36
+
37
+ merged = Lev::Utilities.deep_merge(default_options, options)
38
+ expect(merged).to eq expected
39
+ end
40
+
41
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Routine do
4
+
5
+
6
+
7
+ end
@@ -0,0 +1,22 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
18
+
19
+
20
+ require 'lev'
21
+
22
+ Dir[(File.expand_path('../support', __FILE__)) + ("/**/*.rb")].each { |f| require f }
@@ -0,0 +1,11 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Sprocket do
4
+
5
+ it "should not be valid with bad inputs" do
6
+ sprocket = Sprocket.new(integer_gt_2: 1, text_only_letters: 'abcd4')
7
+ expect(sprocket.valid?).to be_false
8
+ expect(sprocket.errors.count).to eq 2
9
+ end
10
+
11
+ end
@@ -0,0 +1,14 @@
1
+ class CreateSprocket
2
+
3
+ include Lev::Routine
4
+
5
+ protected
6
+
7
+ def exec(number, text)
8
+ sprocket = Sprocket.new(integer_gt_2: number, text_only_letters: text)
9
+ sprocket.valid?
10
+
11
+ transfer_errors_from(sprocket)
12
+ end
13
+
14
+ end
@@ -0,0 +1,10 @@
1
+ class Sprocket
2
+ include ActiveAttr::Model
3
+
4
+ attribute :integer_gt_2, type: Integer
5
+ validates :integer_gt_2, numericality: { only_integer: true,
6
+ greater_than_or_equal_to: 3 }
7
+ attribute :text_only_letters, type: String
8
+ validates :text_only_letters, allow_blank: true,
9
+ format: { with: /\A[a-zA-Z]+\z/, message: "can only contain letters" }
10
+ 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.3
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,56 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-19 00:00:00.000000000 Z
12
+ date: 2013-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activemodel
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activerecord
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: actionpack
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
14
62
  - !ruby/object:Gem::Dependency
15
63
  name: transaction_isolation
16
64
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +139,38 @@ dependencies:
91
139
  - - ! '>='
92
140
  - !ruby/object:Gem::Version
93
141
  version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rspec
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: debugger
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
94
174
  description: Ride the rails but don't touch them.
95
175
  email:
96
176
  - jps@kindlinglabs.com
@@ -99,6 +179,7 @@ extensions: []
99
179
  extra_rdoc_files: []
100
180
  files:
101
181
  - .gitignore
182
+ - .rspec
102
183
  - .ruby-gemset
103
184
  - .ruby-version
104
185
  - Gemfile
@@ -108,23 +189,29 @@ files:
108
189
  - Rakefile
109
190
  - lev.gemspec
110
191
  - lib/lev.rb
111
- - lib/lev/.DS_Store
112
- - lib/lev/algorithm.rb
113
192
  - lib/lev/better_active_model_errors.rb
114
- - lib/lev/delegate_to_algorithm.rb
193
+ - lib/lev/delegate_to_routine.rb
194
+ - lib/lev/error.rb
195
+ - lib/lev/error_transferer.rb
196
+ - lib/lev/error_translator.rb
197
+ - lib/lev/errors.rb
115
198
  - lib/lev/exceptions.rb
116
199
  - lib/lev/form_builder.rb
117
200
  - lib/lev/handle_with.rb
118
201
  - lib/lev/handler.rb
119
- - lib/lev/handler/.DS_Store
120
- - lib/lev/handler/error.rb
121
- - lib/lev/handler/error_transferer.rb
122
- - lib/lev/handler/error_translator.rb
123
- - lib/lev/handler/errors.rb
124
202
  - lib/lev/handler_helper.rb
125
- - lib/lev/routine_nesting.rb
203
+ - lib/lev/routine.rb
204
+ - lib/lev/term_mapper.rb
126
205
  - lib/lev/transaction_isolation.rb
206
+ - lib/lev/utilities.rb
127
207
  - lib/lev/version.rb
208
+ - spec/create_sprocket_spec.rb
209
+ - spec/deep_merge_spec.rb
210
+ - spec/routine_spec.rb
211
+ - spec/spec_helper.rb
212
+ - spec/sprocket_spec.rb
213
+ - spec/support/create_sprocket.rb
214
+ - spec/support/sprocket.rb
128
215
  homepage: http://github.com/lml/lev
129
216
  licenses:
130
217
  - MIT
@@ -140,7 +227,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
227
  version: '0'
141
228
  segments:
142
229
  - 0
143
- hash: 3785122561258895642
230
+ hash: 3159600283927874716
144
231
  required_rubygems_version: !ruby/object:Gem::Requirement
145
232
  none: false
146
233
  requirements:
@@ -149,11 +236,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
236
  version: '0'
150
237
  segments:
151
238
  - 0
152
- hash: 3785122561258895642
239
+ hash: 3159600283927874716
153
240
  requirements: []
154
241
  rubyforge_project:
155
242
  rubygems_version: 1.8.25
156
243
  signing_key:
157
244
  specification_version: 3
158
245
  summary: Ride the rails but don't touch them.
159
- test_files: []
246
+ test_files:
247
+ - spec/create_sprocket_spec.rb
248
+ - spec/deep_merge_spec.rb
249
+ - spec/routine_spec.rb
250
+ - spec/spec_helper.rb
251
+ - spec/sprocket_spec.rb
252
+ - spec/support/create_sprocket.rb
253
+ - spec/support/sprocket.rb
@@ -1,26 +0,0 @@
1
- module Lev
2
- # http://ducktypo.blogspot.com/2010/08/why-inheritance-sucks.html
3
- # http://stackoverflow.com/a/1328093/1664216
4
- module Algorithm
5
-
6
- def self.included(base)
7
- base.extend(ClassMethods)
8
- base.class_eval do
9
- include Lev::RoutineNesting
10
- end
11
- end
12
-
13
- def call(*args, &block)
14
- in_transaction do
15
- exec(*args, &block)
16
- end
17
- end
18
-
19
- module ClassMethods
20
- def call(*args, &block)
21
- new.call(*args, &block)
22
- end
23
- end
24
-
25
- end
26
- end
@@ -1,25 +0,0 @@
1
- # ActiveRecord::Base.delegate_to_algorithm
2
- #
3
- # Let active records delegate certain (likely non-trivial) actions to algoritms
4
- #
5
- # Arguments:
6
- # method: a symbol for the instance method to delegate, e.g. :destroy
7
- # options: a hash of options including...
8
- # :algorithm_klass => The class of the algorithm to delegate to; if not
9
- # given,
10
- ActiveRecord::Base.define_singleton_method(:delegate_to_algorithm) do |method, options={}|
11
- algorithm_klass = options[:algorithm_klass]
12
-
13
- if algorithm_klass.nil?
14
- algorithm_klass_name = "#{method.to_s.capitalize}#{self.name}"
15
- algorithm_klass = Kernel.const_get(algorithm_klass_name)
16
- end
17
-
18
- self.instance_eval do
19
- alias_method "#{method}_original".to_sym, method
20
- define_method method do
21
- algorithm_klass.call(self)
22
- end
23
- end
24
-
25
- end
@@ -1,30 +0,0 @@
1
- module Lev::Handler
2
-
3
- class Error
4
- # need a type or source that can be :activerecord
5
- # when activerecord, data should contain specific fields that
6
- # can be used by generate_message in BetterErrors
7
- attr_accessor :code
8
- attr_accessor :data
9
- attr_accessor :kind
10
- attr_accessor :message
11
- attr_accessor :offending_params
12
-
13
- def initialize(args={})
14
- raise IllegalArgument if args[:code].blank?
15
-
16
- self.code = args[:code]
17
- self.data = args[:data]
18
- self.kind = args[:kind]
19
- self.message = args[:message]
20
-
21
- self.offending_params = args[:offending_params]
22
- self.offending_params = [self.offending_params] if !(self.offending_params.is_a? Array)
23
- end
24
-
25
- def translate
26
- ErrorTranslator.translate(self)
27
- end
28
- end
29
-
30
- end
@@ -1,28 +0,0 @@
1
- module Lev::Handler
2
-
3
- class ErrorTransferer
4
-
5
- def self.transfer(source, handler_target, param_group)
6
- case source
7
- when ActiveRecord::Base, Lev::Paramifier
8
- source.errors.each_with_type_and_message do |attribute, type, message|
9
- handler_target.errors.add(
10
- code: type,
11
- data: {
12
- model: source,
13
- attribute: attribute
14
- },
15
- kind: :activerecord,
16
- message: message,
17
- offending_params: [param_group].flatten << attribute
18
- )
19
- end
20
- else
21
- raise Exception
22
- end
23
-
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,19 +0,0 @@
1
- module Lev::Handler
2
-
3
- class Errors < Array
4
- def add(args)
5
- push(Error.new(args))
6
- end
7
-
8
- def [](key)
9
- self[key]
10
- end
11
-
12
- # Checks to see if the provided param identifier is one of the offending
13
- # params, e.g. has_offending_param?([:my_form, :my_text_field_name])
14
- def has_offending_param?(param)
15
- self.any?{|error| error.offending_params == param}
16
- end
17
- end
18
-
19
- end