tramway 0.4 → 0.4.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 +4 -4
- data/README.md +18 -0
- data/lib/tramway/base_form.rb +27 -8
- data/lib/tramway/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dee256141e588202061885354d7669ee2a5bb1ce99a57a709129031002ab13c8
|
4
|
+
data.tar.gz: 36b036fc2890c2710a12684f78ea36f9a2d8ae7e5f11f252973d81ae905f9e3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8ee38fd18865625ffdb1c9671cedbba4c780d001b47743f3b0be3657e525eb0d96c84529a9023dc6a68acc6507df1646ca712f4c26dd47df8caadc174c66aa3
|
7
|
+
data.tar.gz: 453471063d91beecf588b590008b37546a36b035fed4065499b87f4ef6182ea8fd2a551fcc124f88f1ee07a1ec4df501bfbbafa607a03ea05d1ca28925f5f7c9
|
data/README.md
CHANGED
@@ -249,6 +249,24 @@ class Admin::UsersController < Admin::ApplicationController
|
|
249
249
|
end
|
250
250
|
```
|
251
251
|
|
252
|
+
### Form inheritance
|
253
|
+
|
254
|
+
Tramway Form supports inheritance of `properties`
|
255
|
+
|
256
|
+
**Example**
|
257
|
+
|
258
|
+
```ruby
|
259
|
+
class UserForm < TramwayForm
|
260
|
+
properties :email, :password
|
261
|
+
end
|
262
|
+
|
263
|
+
class AdminForm < UserForm
|
264
|
+
properties :permissions
|
265
|
+
end
|
266
|
+
|
267
|
+
AdminForm.properties # returns [:email, :password, :permissions]
|
268
|
+
```
|
269
|
+
|
252
270
|
### Make flexible and extendable forms
|
253
271
|
|
254
272
|
Tramway Form properties are not mapped to a model. You're able to make extended forms.
|
data/lib/tramway/base_form.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :reek:ClassVariable { enabled: false }
|
3
4
|
module Tramway
|
4
5
|
# Provides form object for Tramway
|
5
6
|
#
|
@@ -17,22 +18,40 @@ module Tramway
|
|
17
18
|
end
|
18
19
|
|
19
20
|
class << self
|
20
|
-
def
|
21
|
-
|
21
|
+
def inherited(subclass)
|
22
|
+
subclass.instance_variable_set(:@properties, [])
|
23
|
+
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def property(attribute)
|
22
28
|
@properties << attribute
|
23
29
|
|
24
30
|
delegate attribute, to: :object
|
25
31
|
end
|
26
32
|
|
27
33
|
def properties(*attributes)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
attributes.any? ? __set_properties(attributes) : __properties
|
35
|
+
end
|
36
|
+
|
37
|
+
def __set_properties(attributes)
|
38
|
+
attributes.each do |attribute|
|
39
|
+
property(attribute)
|
34
40
|
end
|
35
41
|
end
|
42
|
+
|
43
|
+
def __properties
|
44
|
+
(__ancestor_properties + @properties).uniq
|
45
|
+
end
|
46
|
+
|
47
|
+
# :reek:ManualDispatch { enabled: false }
|
48
|
+
def __ancestor_properties(klass = superclass)
|
49
|
+
superklass = klass.superclass
|
50
|
+
|
51
|
+
return [] unless superklass.respond_to?(:properties)
|
52
|
+
|
53
|
+
klass.properties + __ancestor_properties(superklass)
|
54
|
+
end
|
36
55
|
end
|
37
56
|
|
38
57
|
def submit(params)
|
data/lib/tramway/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tramway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kalashnikovisme
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dry-struct
|