preform 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dc370e793ab96fc75b18581696c8b174cf9fb7a
4
- data.tar.gz: 0662d9ce4610cba517b489f53b5b6003479d2be1
3
+ metadata.gz: ed8594873d606d85fe05f7e1cdb91cf00afe9fca
4
+ data.tar.gz: 756d0d056e9377126b2cea6b3a747356ee8727f9
5
5
  SHA512:
6
- metadata.gz: e2c644425393b44b72c9ab87e3a4c41c658867353ba22192cfb0556dbff1d9818cbf00c641a4e7c3c54efa9863a341091154ed303c8a56439e54a0c201f12cdf
7
- data.tar.gz: '08c297085a3b1ee7a5055ddcdee4bf7037ca0f865b6ff8329e07f62a358845b77f0630286315600913949e89b562dd58b9735ae31c9f048ed536328e3ebf8e90'
6
+ metadata.gz: 39651e2c1c00115cbcfeb7dfce5761a75590e8aef6c05fbd8da8534f5d50123e37813cab005a7bb4e3177e87ef80d92e871b263e71e5f347cead2cb02a107bae
7
+ data.tar.gz: f25bfa8e770affd1f7a5aa314c6e0c7d8fc9813b9582ed1c46fdde322ba27be0b144f42f0ca2cf15dfcc155fd958657b865b11b8eebcf25d6b50c9e3e0be03cb
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Preform
2
2
 
3
- A small library for validating user input. It includes mixin,
3
+ A small library for validating user input. It includes a mixin,
4
4
  Validatable, and two opinionated classes that include it: Form, and Field.
5
5
 
6
6
  ## Usage
@@ -19,16 +19,22 @@ Validatable, and two opinionated classes that include it: Form, and Field.
19
19
 
20
20
  `errors`: Returns the errors hash.
21
21
 
22
+ `merge_errors!`: Given another validatable, merges errors into self's errors.
23
+
22
24
  `assert`: Tests a value to see if an error should be added or not. Always returns a boolean so asserts can be nested.
23
25
 
24
26
  #### Form
25
27
 
28
+ `after_initialize`: Override to perform custom initialization behavior.
29
+
26
30
  `params`: Raw params given to the form.
27
31
 
28
32
  `attributes`: Hook that allows you to transform params for use in your application. By default returns raw params.
29
33
 
30
34
  #### Field
31
35
 
36
+ `after_initialize`: Override to perform custom initialization behavior.
37
+
32
38
  `key`: Reader for the form key, used when merging errors into a form.
33
39
 
34
40
  `value`: Raw value to validate.
data/lib/preform.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Preform
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
 
4
4
  module Validatable
5
5
  def validate
@@ -24,6 +24,10 @@ module Preform
24
24
  Hash.new { |hash, key| hash[key] = [] }
25
25
  end
26
26
 
27
+ def merge_errors!(other)
28
+ errors.merge!(other.errors)
29
+ end
30
+
27
31
  def assert(predicate, key, msg)
28
32
  return if predicate
29
33
 
@@ -40,6 +44,12 @@ module Preform
40
44
 
41
45
  def initialize(key, value)
42
46
  @key, @value = key, value
47
+
48
+ after_initialize
49
+ end
50
+
51
+ def after_initialize
52
+ # no op
43
53
  end
44
54
  end
45
55
 
@@ -50,6 +60,12 @@ module Preform
50
60
 
51
61
  def initialize(params)
52
62
  @params = params
63
+
64
+ after_initialize
65
+ end
66
+
67
+ def after_initialize
68
+ # no op
53
69
  end
54
70
 
55
71
  def attributes
data/test/perform_test.rb CHANGED
@@ -21,12 +21,14 @@ end
21
21
  class AccountForm < Preform::Form
22
22
  attr_reader :email, :password
23
23
 
24
- def validate
24
+ def after_initialize
25
25
  @email = EmailField.new(:email, params['email'])
26
26
  @password = PasswordField.new(:password, params['password'])
27
+ end
27
28
 
28
- errors.merge!(email.errors)
29
- errors.merge!(password.errors)
29
+ def validate
30
+ merge_errors! email
31
+ merge_errors! password
30
32
  end
31
33
 
32
34
  def attributes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Weiss