formwandler 0.0.1 → 0.1.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: 1819221ed8cfcaee304d259ef15aa55aaf708048
4
- data.tar.gz: 797085a3cd7806da1f9440b9a6d145648bdf840c
3
+ metadata.gz: 31045e2505c0ef7d1dd3a1f8d104414472f993a3
4
+ data.tar.gz: 4832949e084649a57080971ce6b99b9543b0f771
5
5
  SHA512:
6
- metadata.gz: 0f51d5d47fc62c67637c824993fde8045e763f652ca0394eadd8b93292c1073d7bca93661e39cb2ce0818bbc8c4c226e45012a46687c103ad337b1b3b136ac27
7
- data.tar.gz: d79738347d59093d801c57e56a69db4784a6cac20e0af155f2e91be8f796bc1ff1c58bfdddc8924b112d4093f9239e09d0acb705c604887c05bbd1fe01a5ab2a
6
+ metadata.gz: dcaa3f9f9759283537aad421362e684d55d7c9f8ea3571d935450950887adb3ed6d7ae2553814f06e05241b64f7164c190572491eb5892e3434bc666dbbdae52
7
+ data.tar.gz: 2556aebc204214bd56ad1d7a2a3fa91413011d10620b4d63d678ca42f21498a74cc59d98d96e79bee736302f6c698dd078718b89f260a68bc013ceeaa0f30d52
@@ -62,7 +62,7 @@ module Formwandler
62
62
  end
63
63
 
64
64
  def hidden_options
65
- field_definition.hidden_options&.reject do |_option, value|
65
+ field_definition.hidden_options&.select do |_option, value|
66
66
  _evaluate_value(value)
67
67
  end&.keys || []
68
68
  end
@@ -46,7 +46,7 @@ module Formwandler
46
46
  attr_reader :model_save_order
47
47
  end
48
48
 
49
- attr_reader :fields, :models, :current_user
49
+ attr_reader :models, :current_user
50
50
 
51
51
  def initialize(models: {}, current_user: nil)
52
52
  @models = models.symbolize_keys
@@ -66,11 +66,19 @@ module Formwandler
66
66
  end
67
67
 
68
68
  def field(name)
69
- fields.fetch(name)
69
+ @fields.fetch(name)
70
+ end
71
+
72
+ def fields(*names)
73
+ if names.any?
74
+ @fields.fetch_values(*names)
75
+ else
76
+ @fields.values
77
+ end
70
78
  end
71
79
 
72
80
  def fields_for_model(model)
73
- fields.values.select { |field| field.model == model }
81
+ fields.select { |field| field.model == model }
74
82
  end
75
83
 
76
84
  def models_valid?
@@ -103,7 +111,7 @@ module Formwandler
103
111
  end
104
112
 
105
113
  def assign_defaults
106
- fields.values.each do |field|
114
+ fields.each do |field|
107
115
  next unless field.default?
108
116
  send("#{field.name}=", field.default) if send(field.name).nil?
109
117
  end
@@ -120,7 +128,7 @@ module Formwandler
120
128
  end
121
129
 
122
130
  def permitted_params(params)
123
- visible_fields = fields.values.reject(&:hidden?).map(&:name)
131
+ visible_fields = fields.reject(&:hidden?).map(&:name)
124
132
  delocalizations = fields.transform_values(&:delocalize).compact
125
133
  params = ActionController::Parameters.new(params) if params.is_a?(Hash)
126
134
  params.require(model_name.param_key).permit(*visible_fields).delocalize(delocalizations)
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.0.1
4
+ version: 0.1.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: 2017-09-05 00:00:00.000000000 Z
11
+ date: 2017-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Create form objects for multiple models, dynamically mark fields as hidden
28
42
  or disabled and even hide select options dynamically
29
43
  email: sbilharz@heilmannsoftware.de