formify 0.16.0 → 0.17.7
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +0 -6
- data/lib/formify/version.rb +1 -1
- data/lib/generators/form/form_generator.rb +19 -2
- data/lib/generators/form/templates/form.rb.tt +17 -5
- data/lib/generators/form/templates/form_spec.rb.tt +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d85707d12681f8344a9b5a8a12fae50ed194fe5c051dcbe6c1ccfc143df843
|
4
|
+
data.tar.gz: a6a565b5acfc240738049529103d90beabdd99f10b841265eb080e32afb50105
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a72509aadd70c77d3d8f23f1ad7c5148c5022658ce2c82db2d1b0020a8d4b36519c2dcaa958721d51aa24e70b6d474b3a24bc5b81a9c8e399888dc8b326f1c3
|
7
|
+
data.tar.gz: 37398a9a1fb561d7d9e9c2467dfdf9d5b61ea4295e3f92803a4a9df1d222a66bacd620aad597a3168c450cdf61c2d0e3433c248b8a9ff51038b2f23618d6489f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -122,42 +122,36 @@ describe Forms::Widgets::Create, type: :form do
|
|
122
122
|
it { expect(value).to be_a(Widget) } # Model name inferred
|
123
123
|
|
124
124
|
context '#bar' do
|
125
|
-
# Attribute: :bar
|
126
125
|
it { expect_error_with_missing_attribute(:bar) }
|
127
126
|
xit { expect_error_with_attribute_value(:bar, BAR_BAD_VALUE, message: nil) } # :message is optional
|
128
127
|
xit { expect_valid_with_attribute_value(:bar, BAR_GOOD_VALUE) }
|
129
128
|
end
|
130
129
|
|
131
130
|
context '#baz' do
|
132
|
-
# Attribute: :baz
|
133
131
|
it { expect_error_with_missing_attribute(:baz) }
|
134
132
|
xit { expect_error_with_attribute_value(:baz, BAZ_BAD_VALUE, message: nil) } # :message is optional
|
135
133
|
xit { expect_valid_with_attribute_value(:baz, BAZ_GOOD_VALUE) }
|
136
134
|
end
|
137
135
|
|
138
136
|
context '#created_by' do
|
139
|
-
# Attribute: :created_by
|
140
137
|
it { expect_error_with_missing_attribute(:created_by) }
|
141
138
|
xit { expect_error_with_attribute_value(:created_by, CREATED_BY_BAD_VALUE, message: nil) } # :message is optional
|
142
139
|
xit { expect_valid_with_attribute_value(:created_by, CREATED_BY_GOOD_VALUE) }
|
143
140
|
end
|
144
141
|
|
145
142
|
context '#foo' do
|
146
|
-
# Attribute: :foo
|
147
143
|
it { expect_error_with_missing_attribute(:foo) }
|
148
144
|
xit { expect_error_with_attribute_value(:foo, FOO_BAD_VALUE, message: nil) } # :message is optional
|
149
145
|
xit { expect_valid_with_attribute_value(:foo, FOO_GOOD_VALUE) }
|
150
146
|
end
|
151
147
|
|
152
148
|
context '#owner' do
|
153
|
-
# Attribute: :owner
|
154
149
|
it { expect_error_with_missing_attribute(:owner) }
|
155
150
|
xit { expect_error_with_attribute_value(:owner, OWNER_BAD_VALUE, message: nil) } # :message is optional
|
156
151
|
xit { expect_valid_with_attribute_value(:owner, OWNER_GOOD_VALUE) }
|
157
152
|
end
|
158
153
|
|
159
154
|
context '#owner_attribute' do
|
160
|
-
# Attribute: :owner_attribute
|
161
155
|
it { expect_error_with_missing_attribute(:owner_attribute) }
|
162
156
|
xit { expect_error_with_attribute_value(:owner_attribute, OWNER_ATTRIBUTE_BAD_VALUE, message: nil) } # :message is optional
|
163
157
|
xit { expect_valid_with_attribute_value(:owner_attribute, OWNER_ATTRIBUTE_GOOD_VALUE) }
|
data/lib/formify/version.rb
CHANGED
@@ -49,8 +49,11 @@ class FormGenerator < Rails::Generators::NamedBase
|
|
49
49
|
.sort
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
53
|
-
@
|
52
|
+
def attributes_with_delegates
|
53
|
+
@attributes_with_delegates ||= attributes_and_delegates
|
54
|
+
.select { |k, v| v.present? }
|
55
|
+
.keys
|
56
|
+
.sort
|
54
57
|
end
|
55
58
|
|
56
59
|
def attributes_and_delegates
|
@@ -69,6 +72,10 @@ class FormGenerator < Rails::Generators::NamedBase
|
|
69
72
|
@collection_name ||= collection.camelcase
|
70
73
|
end
|
71
74
|
|
75
|
+
def create?
|
76
|
+
form.downcase.include?('create')
|
77
|
+
end
|
78
|
+
|
72
79
|
def delegated_attributes
|
73
80
|
@delegated_attributes ||= attributes_and_delegates
|
74
81
|
.select { |_k, v| v.sort!.present? }
|
@@ -109,6 +116,16 @@ class FormGenerator < Rails::Generators::NamedBase
|
|
109
116
|
@pluralize_collection ||= options[:pluralize_collection]
|
110
117
|
end
|
111
118
|
|
119
|
+
def return_attribute
|
120
|
+
@return_attribute ||= begin
|
121
|
+
if all_attributes.include?(collection.singularize)
|
122
|
+
collection.singularize
|
123
|
+
else
|
124
|
+
form_attributes.split(':').first
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
112
129
|
def scopes
|
113
130
|
@scopes ||= split_name[0..-3].map(&:underscore)
|
114
131
|
end
|
@@ -4,9 +4,9 @@
|
|
4
4
|
class <%= form_name %>
|
5
5
|
include Formify::Form
|
6
6
|
|
7
|
-
attr_accessor :<%=
|
8
|
-
<%
|
9
|
-
:<%= attr %><%= ',' unless
|
7
|
+
attr_accessor :<%= attributes_with_delegates.first %><%= ',' if attributes_with_delegates.count > 1 %>
|
8
|
+
<% attributes_with_delegates[1..-1].each_with_index do |attr, i| -%>
|
9
|
+
:<%= attr %><%= ',' unless attributes_with_delegates.count - 2 == i %>
|
10
10
|
<% end -%>
|
11
11
|
|
12
12
|
<% delegated_attributes.each do |to_attr, delegates| -%>
|
@@ -17,6 +17,8 @@ class <%= form_name %>
|
|
17
17
|
to: :<%= to_attr %>
|
18
18
|
<% end -%>
|
19
19
|
|
20
|
+
before_validation :before_validation_do_something
|
21
|
+
|
20
22
|
validates_presence_of :<%= all_attributes.first %><%= ',' if all_attributes.count > 1 %>
|
21
23
|
<% all_attributes[1..-1].each_with_index do |attr, i| -%>
|
22
24
|
:<%= attr %><%= ',' unless all_attributes.count - 2 == i %>
|
@@ -24,7 +26,11 @@ class <%= form_name %>
|
|
24
26
|
|
25
27
|
# validate :validate_something
|
26
28
|
|
27
|
-
initialize_with :<%=
|
29
|
+
initialize_with :<%= attributes_with_delegates.join(', :') %> do |attributes|
|
30
|
+
<% if create? -%>
|
31
|
+
self.<%= collection.singularize %> ||= <%= inferred_model_name %>.new
|
32
|
+
|
33
|
+
<% end -%>
|
28
34
|
puts attributes
|
29
35
|
end
|
30
36
|
|
@@ -34,15 +40,21 @@ class <%= form_name %>
|
|
34
40
|
with_advisory_lock_transaction(:foo) do
|
35
41
|
validate_or_fail
|
36
42
|
.and_then { <%= name.split('/').reverse[0..1].map(&:singularize).join('_').underscore %> }
|
37
|
-
.and_then { success(<%=
|
43
|
+
.and_then { success(<%= return_attribute %>) }
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
41
47
|
private
|
42
48
|
|
43
49
|
def <%= name.split('/').reverse[0..1].map(&:singularize).join('_').underscore %>
|
50
|
+
raise NotImplementedError
|
51
|
+
|
52
|
+
success(<%= return_attribute %>)
|
44
53
|
end
|
45
54
|
|
55
|
+
# def before_validation_do_something
|
56
|
+
# end
|
57
|
+
|
46
58
|
# def validate_something
|
47
59
|
# end
|
48
60
|
end
|
@@ -23,7 +23,6 @@ describe Forms::<%= class_name %>, type: :form do
|
|
23
23
|
|
24
24
|
<% all_attributes.each do |attr| -%>
|
25
25
|
context '#<%= attr %>' do
|
26
|
-
# Attribute: :<%= attr %>
|
27
26
|
it { expect_error_with_missing_attribute(:<%= attr %>) }
|
28
27
|
xit { expect_error_with_attribute_value(:<%= attr %>, <%= attr.upcase %>_BAD_VALUE, message: nil) } # :message is optional
|
29
28
|
xit { expect_valid_with_attribute_value(:<%= attr %>, <%= attr.upcase %>_GOOD_VALUE) }
|