motion_model 0.3.3 → 0.3.4

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/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 2012-01-14: Fixed problem where data returned from forms was of type NSString, which
2
+ confused some monkey-patching code.
3
+ Changed before_ hooks such that handlers returning false would terminate
4
+ the process. So, if before_save returns anything other than false, the
5
+ save continues. Only if before_save returns false does the save get
6
+ interrupted.
7
+ Fixed immutable string issue in validations.
8
+
1
9
  2012-01-09: Added automatic date/timestamp support for created_at and updated_at columns
2
10
  Added Hash extension except, Array introspection methods has_hash_key? and
3
11
  has_hash_value?
@@ -426,8 +426,9 @@ module MotionModel
426
426
  end
427
427
 
428
428
  def call_hooks(hook_name, &block)
429
- call_hook('before', hook_name)
430
- block.call
429
+ result = call_hook('before', hook_name)
430
+ # returning false from a before_ hook stops the process
431
+ block.call if result !== false && block_given?
431
432
  call_hook('after', hook_name)
432
433
  end
433
434
 
@@ -30,19 +30,23 @@ module MotionModel
30
30
  end
31
31
 
32
32
  def cast_to_array(arg)
33
- arg.is_a?(Array) ? arg : arg.to_a
33
+ arg.is_a?(Array) ? Array(arg) : arg.to_a
34
+ end
35
+
36
+ def cast_to_string(arg)
37
+ String(arg)
34
38
  end
35
39
 
36
40
  def cast_to_type(column_name, arg) #nodoc
37
41
  return nil if arg.nil? && ![ :boolean, :bool ].include?(type(column_name))
38
42
 
39
43
  return case type(column_name)
40
- when :string then arg.to_s
44
+ when :string then cast_to_string(arg)
41
45
  when :boolean, :bool then cast_to_bool(arg)
42
46
  when :int, :integer, :belongs_to_id then cast_to_integer(arg)
43
47
  when :float, :double then cast_to_float(arg)
44
48
  when :date then cast_to_date(arg)
45
- when :text then arg.to_s
49
+ when :text then cast_to_string(arg)
46
50
  when :array then cast_to_array(arg)
47
51
  else
48
52
  raise ArgumentError.new("type #{column_name} : #{type(column_name)} is not possible to cast.")
@@ -97,8 +97,7 @@ module MotionModel
97
97
  validation.each_pair do |validation_type, setting|
98
98
  if self.respond_to? validation_method(validation_type)
99
99
  value = self.send(field)
100
- value.strip! if value.is_a?(String)
101
- result &&= self.send(validation_method(validation_type), field, value, setting)
100
+ result &&= self.send(validation_method(validation_type), field, value.is_a?(String) ? value.strip : value, setting)
102
101
  else
103
102
  ex = ValidationSpecificationError.new("unknown validation type :#{validation_type.to_s}")
104
103
  end
@@ -1,3 +1,3 @@
1
1
  module MotionModel
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
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-01-09 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bubble-wrap