rectify 0.5.4 → 0.6.0

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: 498c07c4691e3991bc14760443152f01a768841c
4
- data.tar.gz: 23cc732b6058b32a9f395b7fc4f9c9c7ea65f1dd
3
+ metadata.gz: b8fedfe52a78eea51145b0f2d0a5e1edf6e92b25
4
+ data.tar.gz: e380f406cdb8c4de9883ecdc0ae62eb09c3eef44
5
5
  SHA512:
6
- metadata.gz: b4841dbbb4ca5e6e99ca901845bba5847735d567386fae734b0d52cbf41cc036a0002fcaa35e0145b907947a02781558ae5bc8f3249e215f5df78b1f6b8ebeef
7
- data.tar.gz: dfdc764ce3e6d45a10735a9c838f73c36fd97249c1c4a27cf0cf83556714e17f623cd3fbcce9e2fea437720cc8e5f4ee967cd951e1da0e75f697b3de446518a6
6
+ metadata.gz: 96d0587eba88068ee4085979b976b398ff87902ba40710f902eaba16f06e57634626decca44fb3b3bfd0f687bdfa088e0062758fd1e3742e395d415875d55cd1
7
+ data.tar.gz: 6a9d47abdfc59d99ccd67914693969c8a1da62945e9a150edae77c38e830b8c9d8745c885743dd606ec85eb2dc84374abf1e38a7fbc6efb10cf81b52cf2a150d
data/lib/rectify/form.rb CHANGED
@@ -22,6 +22,10 @@ module Rectify
22
22
  Rectify::BuildFormFromModel.new(self, model).build
23
23
  end
24
24
 
25
+ def self.from_json(json)
26
+ from_params(JSON.parse(json))
27
+ end
28
+
25
29
  def self.mimic(model_name)
26
30
  @model_name = model_name.to_s.underscore.to_sym
27
31
  end
@@ -1,3 +1,3 @@
1
1
  module Rectify
2
- VERSION = "0.5.4"
2
+ VERSION = "0.6.0"
3
3
  end
data/readme.md CHANGED
@@ -103,7 +103,7 @@ and Presenters.
103
103
 
104
104
  ## Form Objects
105
105
 
106
- The role of the Form Object is to mange the input data for a given action. It
106
+ The role of the Form Object is to manage the input data for a given action. It
107
107
  validates data and only allows whitelisted attributes (replacing the need for
108
108
  Strong Parameters). This is a departure from "The Rails Way" where the model
109
109
  contains the validations. Form Objects help to reduce the weight of your models
@@ -283,7 +283,7 @@ form.ip_address # => "1.2.3.4"
283
283
 
284
284
  **Model**
285
285
 
286
- The final way is to pass a Ruby object instance (which is normally an ActiveModel
286
+ You can pass a Ruby object instance (which is normally an ActiveModel
287
287
  but can be any PORO) to the form to populate it's attribute values. This is useful
288
288
  when editing a model:
289
289
 
@@ -328,6 +328,30 @@ want to collect or show in your forms, not something that is linked to a model.
328
328
  This allows you to create any form that you like which doesn't need to match the
329
329
  representation of the data in the database.
330
330
 
331
+ **JSON**
332
+
333
+ You can also populate a form object from a JSON string. Just pass it in to the
334
+ `.from_json` class method and the form will be created with the attributes
335
+ populated by matching names:
336
+
337
+ ```ruby
338
+ json = <<-JSON
339
+ {
340
+ "first_name": "Andy",
341
+ "age": 38
342
+ }
343
+ JSON
344
+
345
+ form = UserForm.from_json(json)
346
+
347
+ form.first_name # => "Andy"
348
+ form.age # => 38
349
+ ```
350
+
351
+ Populating the form from JSON can be useful when dealing with API requests into
352
+ your system. Which allows you to easily access data and perform validation if
353
+ required.
354
+
331
355
  ### Validations
332
356
 
333
357
  Rectify includes `ActiveModel::Validations` for you so you can use all of the
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rectify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Pike
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-31 00:00:00.000000000 Z
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus