formify 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/formify/form.rb +28 -20
- data/lib/formify/version.rb +1 -1
- data/lib/generators/form/templates/form.rb.tt +13 -0
- 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: 72de11fb4c4933d16cd59cce57c64c037cc7abb16bd82d3d6bdf7b865e403c46
|
4
|
+
data.tar.gz: 0f3e5a864f982eb1a9a56b7694e073d69da47b793233f42a3cea203027ea3601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28f012f82c0bec95ceceb3a9ac9611887e197aa42ef0786a68bc3360b810bd47f9de5d8c021f4b581d9db4bacae9599d6c3eafde4dab9a0179395d3fa63f4259
|
7
|
+
data.tar.gz: 675d7a158bcb082a598fa0020d328500bfab58c550fb6df8ad25ebe7e0ff5b6bba507e64afb6c3aed1b224b68635765ffeb052bdd9319373372c3549ea77441c
|
data/Gemfile.lock
CHANGED
data/lib/formify/form.rb
CHANGED
@@ -9,10 +9,38 @@ module Formify
|
|
9
9
|
include ActiveModel::Validations
|
10
10
|
include ActiveModel::Validations::Callbacks
|
11
11
|
|
12
|
+
def failure(*args)
|
13
|
+
Resonad.Failure(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def params
|
17
|
+
self.class.params
|
18
|
+
end
|
19
|
+
|
20
|
+
def return_self
|
21
|
+
Resonad.Success(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def success(*args)
|
25
|
+
Resonad.Success(*args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def translation_data
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
|
12
32
|
def t(*args, **keywords)
|
13
33
|
I18n.t(*args, **keywords)
|
14
34
|
end
|
15
35
|
|
36
|
+
def translation_success
|
37
|
+
split_name = self.class.name.split('::')
|
38
|
+
split_name.shift
|
39
|
+
action = split_name.pop.underscore
|
40
|
+
key = split_name.map(&:underscore).push(action).push(:success).join('.')
|
41
|
+
return t(key) if I18n.exists?(key, translation_data)
|
42
|
+
end
|
43
|
+
|
16
44
|
def validate_or_fail(*instances)
|
17
45
|
unless valid?
|
18
46
|
return Resonad.Failure(
|
@@ -33,22 +61,6 @@ module Formify
|
|
33
61
|
Resonad.Success
|
34
62
|
end
|
35
63
|
|
36
|
-
def return_self
|
37
|
-
Resonad.Success(self)
|
38
|
-
end
|
39
|
-
|
40
|
-
def translation_data
|
41
|
-
{}
|
42
|
-
end
|
43
|
-
|
44
|
-
def translation_success
|
45
|
-
split_name = self.class.name.split('::')
|
46
|
-
split_name.shift
|
47
|
-
action = split_name.pop.underscore
|
48
|
-
key = split_name.map(&:underscore).push(action).push(:success).join('.')
|
49
|
-
return t(key) if I18n.exists?(key, translation_data)
|
50
|
-
end
|
51
|
-
|
52
64
|
def with_advisory_lock(*keys, **args)
|
53
65
|
key = keys.map do |k|
|
54
66
|
if k.is_a?(String)
|
@@ -75,10 +87,6 @@ module Formify
|
|
75
87
|
|
76
88
|
with_advisory_lock_transaction_result
|
77
89
|
end
|
78
|
-
|
79
|
-
def params
|
80
|
-
self.class.params
|
81
|
-
end
|
82
90
|
end
|
83
91
|
|
84
92
|
class_methods do
|
data/lib/formify/version.rb
CHANGED
@@ -4,8 +4,21 @@
|
|
4
4
|
class <%= name.split('/').last.to_s.camelcase %>
|
5
5
|
include Formify::Form
|
6
6
|
|
7
|
+
def initialize(attributes = {})
|
8
|
+
raise NotImplementedError
|
9
|
+
|
10
|
+
self.fixed_attr = attributes[:fixed_attr]
|
11
|
+
super(attributes)
|
12
|
+
end
|
13
|
+
|
7
14
|
def save
|
8
15
|
raise NotImplementedError
|
16
|
+
|
17
|
+
with_advisory_lock_transaction(:foo) do
|
18
|
+
validate_or_fail
|
19
|
+
.and_then { method }
|
20
|
+
.and_then { success(object) }
|
21
|
+
end
|
9
22
|
end
|
10
23
|
end
|
11
24
|
<% end -%>
|