on_form 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d7dd5ed97fb50b463cd137f4e37cd54a6b5039f
4
- data.tar.gz: cf2be44d209f36980cb248e89498060ae50374a8
3
+ metadata.gz: 820b56db21bed598a2c4c4fbef8aa5c33cabc693
4
+ data.tar.gz: 7cd239b39707c8fefa12ba3acec8c2cbe3d733b4
5
5
  SHA512:
6
- metadata.gz: c967c12d103f110b2932b03e06b4c8e708e1623abc970270c0dc4fdd2f33ccab5936ecccc440e0b8b4922cdac099258eb37b735bd068cef5727c7b62ea2108f1
7
- data.tar.gz: b26ae23736314ecfa179e4c380fa4d8e91ea7a09cd18ccd6fae5c9b9c64778225698b040e7bfbe41f67027cfcb90d2176b6f6bc1e0299373c441cc7eb1857756
6
+ metadata.gz: 897e50e32ef49cf93fea57d5487c750b8c3ed8e65d8610dce0ffb657f6171697b329bfc7125175883223e529bb857442fc5381d34c4ad08f8568721d0194ad5d
7
+ data.tar.gz: eefe006c8c937acad840b960076233592eed058c4265ca5aaa8e86aa0176a047c4b57d3b962b9aa0d9368431d687a1fbec8a67a322afce90cd273f44787b23e9
data/CHANGES.md CHANGED
@@ -1,10 +1,15 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 2.01
5
+ ----
6
+ * Fix regressions in support for Rails 4.2.
7
+ * Support some additional attribute methods such as `*_was` and `*_changed?`.
8
+
4
9
  2.00
5
10
  ----
6
- * New expose syntax to support prefix:, suffix:, and as: options
11
+ * New expose syntax to support prefix:, suffix:, and as: options.
7
12
 
8
13
  1.00
9
14
  ----
10
- * First public release
15
+ * First public release.
@@ -54,9 +54,11 @@ module OnForm
54
54
  self.class.exposed_attributes.keys.collect { |backing_model_name| backing_model_instance(backing_model_name) }
55
55
  end
56
56
 
57
- def backing_model_for_attribute(exposed_name)
57
+ def backing_for_attribute(exposed_name)
58
58
  self.class.exposed_attributes.each do |backing_model_name, attribute_mappings|
59
- return backing_model_instance(backing_model_name) if attribute_mappings[exposed_name.to_sym]
59
+ if backing_name = attribute_mappings[exposed_name.to_sym]
60
+ return [backing_model_instance(backing_model_name), backing_name]
61
+ end
60
62
  end
61
63
  nil
62
64
  end
data/lib/on_form/form.rb CHANGED
@@ -40,6 +40,8 @@ module OnForm
40
40
  define_method(exposed_name) { backing_model_instance(backing_model_name).send(backing_name) }
41
41
  define_method("#{exposed_name}_before_type_cast") { backing_model_instance(backing_model_name).send("#{backing_name}_before_type_cast") }
42
42
  define_method("#{exposed_name}?") { backing_model_instance(backing_model_name).send("#{backing_name}?") }
43
+ define_method("#{exposed_name}_changed?") { backing_model_instance(backing_model_name).send("#{backing_name}_changed?") }
44
+ define_method("#{exposed_name}_was") { backing_model_instance(backing_model_name).send("#{backing_name}_was") }
43
45
  define_method("#{exposed_name}=") { |arg| backing_model_instance(backing_model_name).send("#{backing_name}=", arg) }
44
46
  end
45
47
  end
@@ -1,6 +1,7 @@
1
- # unlike the rest of this library, which is new code, the code in this source file is from ActiveRecord, and
2
- # is used to provide compatibility wrappers with different versions of ActiveRecord. please keep it separate
3
- # so we can see where everything came from and what may need to be kept in sync with ActiveRecord refactors.
1
+ # unlike the rest of this library, which is new code, the code in this source file is from Rails, and is used to
2
+ # provide compatibility wrappers with different versions of ActiveRecord/ActiveModel. please keep it separate so
3
+ # we can see where everything came from, and what may need to be kept in sync with refactors in those libraries.
4
+
4
5
  module OnForm
5
6
  module MultiparameterAttributes
6
7
  # Instantiates objects for all attribute classes that needs more than one constructor parameter. This is done
@@ -22,7 +23,8 @@ module OnForm
22
23
  if defined?(ActiveRecord::AttributeAssignment::MultiparameterAttribute)
23
24
  # ActiveRecord 4.2 and below: you must use MultiparameterAttribute to construct the attribute value.
24
25
  # we therefore have to look up which model the attribute actually lives on.
25
- send("#{name}=", ActiveRecord::AttributeAssignment::MultiparameterAttribute.new(backing_model_for_attribute(name), name, values_with_empty_parameters).read_value)
26
+ backing_model, backing_name = backing_for_attribute(name)
27
+ send("#{name}=", ActiveRecord::AttributeAssignment::MultiparameterAttribute.new(backing_model, backing_name.to_s, values_with_empty_parameters).read_value)
26
28
  else
27
29
  # ActiveRecord 5.0+: you can assign the indexed hash to the column and it will construct the value for you.
28
30
  if values_with_empty_parameters.each_value.all?(&:nil?)
@@ -65,3 +67,20 @@ module OnForm
65
67
  end
66
68
  end
67
69
  end
70
+
71
+
72
+ require 'active_model/validations'
73
+
74
+ unless ActiveModel.const_defined?(:ValidationError)
75
+ module ActiveModel
76
+ class ValidationError < StandardError
77
+ attr_reader :model
78
+
79
+ def initialize(model)
80
+ @model = model
81
+ errors = @model.errors.full_messages.join(", ")
82
+ super(I18n.t(:"#{@model.class.i18n_scope}.errors.messages.model_invalid", errors: errors, default: :"errors.messages.model_invalid"))
83
+ end
84
+ end
85
+ end
86
+ end
@@ -1,3 +1,3 @@
1
1
  module OnForm
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
data/lib/on_form.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require "active_model"
2
2
  require "active_record"
3
3
  require "on_form/version"
4
+ require "on_form/rails_compat"
4
5
  require "on_form/attributes"
5
- require "on_form/multiparameter_attributes"
6
6
  require "on_form/errors"
7
7
  require "on_form/saving"
8
8
  require "on_form/form"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: on_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Bryant
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-26 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -100,7 +100,7 @@ files:
100
100
  - lib/on_form/attributes.rb
101
101
  - lib/on_form/errors.rb
102
102
  - lib/on_form/form.rb
103
- - lib/on_form/multiparameter_attributes.rb
103
+ - lib/on_form/rails_compat.rb
104
104
  - lib/on_form/saving.rb
105
105
  - lib/on_form/version.rb
106
106
  - on_form.gemspec