tramway 0.4 → 0.4.1

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: 68a5dd780d7427b0c2075f140c891af3a4c33210c88a00d86e33279dc27e6c28
4
- data.tar.gz: 63701d608f5545ea95e98fac522624cc34092199fe839b16ba579d9c461c0383
3
+ metadata.gz: dee256141e588202061885354d7669ee2a5bb1ce99a57a709129031002ab13c8
4
+ data.tar.gz: 36b036fc2890c2710a12684f78ea36f9a2d8ae7e5f11f252973d81ae905f9e3a
5
5
  SHA512:
6
- metadata.gz: 8e6c295607acc32db6b7a0bea211ddb9ba2d8e2ca141804bce78b7b51fb74a08478c38ead05962f56ecd226a57b2e7398b97c86ac6dcc7aa46c3862bd8a49f30
7
- data.tar.gz: bd89050c6d5b3391f457eea7a277cdaaa53c3fbe1f20a0567c39b659ab8a3187d2f161bed38a6b9226782191b884fe94eb63d7e7f8aa292e8ff121dcf149c521
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.
@@ -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 property(attribute, _proc_obj = nil)
21
- @properties ||= []
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
- if attributes.any?
29
- attributes.each do |attribute|
30
- property(attribute)
31
- end
32
- else
33
- @properties || []
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.4'
4
+ VERSION = '0.4.1'
5
5
  end
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: '0.4'
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-01-20 00:00:00.000000000 Z
12
+ date: 2024-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-struct