formwandler 0.5.0 → 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
  SHA256:
3
- metadata.gz: 4d04197f5a3301a80069f8b0200228445e13ed4d0acfe967db3785d2a62197b8
4
- data.tar.gz: 00e39bc2876b1aa9e782a28d4dd61b898b465618cd3bbc3e7a2332f0c3d6f3ac
3
+ metadata.gz: 8a45d189660c8aace9e7271c8d9dc110962a75954c538b8e0ffc29c882f0cde4
4
+ data.tar.gz: 85d1558cfd2507a7bbf57cb4c21f5c41f205df3230a49e408d4333e2c9fa40ed
5
5
  SHA512:
6
- metadata.gz: 102eb373dc65dc92b07fb6f495bd265f72713c4a8193628911dd5299a083fc4e2b2da8fa5d6286a2ead2acf097c3a08a9c63be7c0e86ea60e1a69eaab217b5f7
7
- data.tar.gz: 2e049c3cc06cc1e55dd7411e716ab87a15ef179ed16704700912e42bd7e75d6d8d31a6aadf60f4c9b617e10477f163a3457ae4441ef9d53a4c36d06ca96e4a43
6
+ metadata.gz: 136d046b2a96878ecdc22c39a8e1c4ff400a8e211d063397ad8e1d38aed2ddcf30e342e50c21292f6fbfbbefc809569be90fcd13c897d0c9bb5b05b1bdf280bc
7
+ data.tar.gz: f9fdf3e938ec7476755097233005a173c8b6ef68f4d8ec2ff24cd33edc1b300885f9a36392a09ba86de0516d38c7caa102bf2381cbd96b98886ad145906ca2f8
@@ -4,18 +4,12 @@ require_relative 'field_value_transformer'
4
4
 
5
5
  module Formwandler
6
6
  class FieldDefinition
7
- attr_reader :name, :hidden, :disabled, :default, :delocalize, :model, :source, :options, :array
7
+ attr_reader :name
8
+ attr_accessor :hidden, :disabled, :default, :delocalize, :model, :source, :options, :array
8
9
 
9
- def initialize(name, hidden: false, disabled: false, default: nil, delocalize: nil, model: nil, source: nil, options: nil, array: false)
10
+ def initialize(name)
10
11
  @name = name
11
- @hidden = hidden
12
- @disabled = disabled
13
- @default = default
14
- @delocalize = delocalize
15
- @model = model
16
- @source = source || name
17
- @options = options
18
- @array = array
12
+ set_defaults
19
13
  end
20
14
 
21
15
  def hide_option(name, value = true)
@@ -41,5 +35,16 @@ module Formwandler
41
35
  private
42
36
 
43
37
  attr_reader :value_transformer
38
+
39
+ def set_defaults
40
+ @hidden = false
41
+ @disabled = false
42
+ @default = nil
43
+ @delocalize = nil
44
+ @model = nil
45
+ @source = name
46
+ @options = nil
47
+ @array = false
48
+ end
44
49
  end
45
50
  end
@@ -19,9 +19,12 @@ module Formwandler
19
19
  end
20
20
 
21
21
  def field(name, opts = {}, &block)
22
- field_definition = FieldDefinition.new(name, opts)
23
- field_definitions[name] = field_definition
24
-
22
+ field_definition = field_definitions[name] ||= FieldDefinition.new(name)
23
+ opts.each do |key, value|
24
+ field_definition.public_send("#{key}=", value)
25
+ rescue NoMethodError
26
+ raise ArgumentError, "Invalid option #{key}"
27
+ end
25
28
  field_definition.instance_exec(&block) if block_given?
26
29
 
27
30
  attribute_accessor(name)
@@ -1,3 +1,3 @@
1
1
  module Formwandler
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formwandler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Bilharz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-05 00:00:00.000000000 Z
11
+ date: 2018-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails