tramway 0.4.3 → 0.4.4

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: cae2dee0a95959ec9a4d2edb886ffd6fbd2ec305770e0ba78f9dc09f04d641ce
4
- data.tar.gz: e3d287cd49a4b181279aa8574bec79364af8b9c0b240299cddb3f7ae18dfcd55
3
+ metadata.gz: b43fe918fc6610c50f4ed68ddc2487d295084f931fe77cfcdc5bdb82cc518007
4
+ data.tar.gz: 1e72ed61a083e7ba35daf01137678e3858f081cb46148acb16b1c2b7999de207
5
5
  SHA512:
6
- metadata.gz: a2cdabe494be288cc8c1d538b727e41cfa0ce2d8d0c49ca8be1561dbc1780e4ba5826be7ee9c9d7c62dff3749b0a94568f747d03d35405c74a22e62b24e210d3
7
- data.tar.gz: 36b601a82003ea9c623247d57a068b60fb98998265d7d5dc2a9f505c8e8accbf7ba4e7831bf36601fb05e8b952600bd16900c84db7e8fe4b421b408349914ca5
6
+ metadata.gz: 86065ebdaf2fe77f1d7599723a42189fa1ac3e49e8de52fd6b94d28911e4060ee9edc5b2f4501a38fc8d1697456c80bd9d8ff9a40ea924154b82303ac728e67e
7
+ data.tar.gz: bf80442224d4659ca1258258418e1f42490caf20924ea22e6fa6be26ea08e2d567b381fc5a842ef53f9aa2e40537ea1946270d369e256d74989acf14b50dd267
data/README.md CHANGED
@@ -8,7 +8,7 @@ Unite Ruby on Rails brilliance. Streamline development with Tramway.
8
8
  * [Tramway Form](https://github.com/Purple-Magic/tramway#tramway-form)
9
9
  * [Tramway Navbar](https://github.com/Purple-Magic/tramway#tramway-navbar)
10
10
  * [Tailwind-styled forms](https://github.com/Purple-Magic/tramway#tailwind-styled-forms)
11
- * [Tailwind-styled pagination](https://github.com/Purple-Magic/tramway#tailwind-styled-pagination)
11
+ * [Tailwind-styled pagination](https://github.com/Purple-Magic/tramway?tab=readme-ov-file#tailwind-styled-pagination-for-kaminari)
12
12
 
13
13
  ## Installation
14
14
  Add this line to your application's Gemfile:
@@ -125,6 +125,10 @@ user = nil
125
125
  UserDecorator.decorate user # => nil
126
126
  ```
127
127
 
128
+ #### Update and Destroy
129
+
130
+ Read [behave_as_ar](https://github.com/Purple-Magic/tramway#behave_as_ar) section
131
+
128
132
  ### Tramway Form
129
133
 
130
134
  Tramway provides **convenient** form objects for Rails applications. List properties you want to change and the rules in Form classes. No controllers overloading.
@@ -303,6 +307,10 @@ class UserForm < Tramway::BaseForm
303
307
  end
304
308
  ```
305
309
 
310
+ #### Update and Destroy
311
+
312
+ Read [behave_as_ar](https://github.com/Purple-Magic/tramway#behave_as_ar) section
313
+
306
314
  ### Tramway Navbar
307
315
 
308
316
  Tramway provides DSL for rendering Tailwind Navgiation bar.
@@ -421,6 +429,10 @@ end
421
429
 
422
430
  Pagination buttons looks like [this](https://play.tailwindcss.com/mqgDS5l9oY)
423
431
 
432
+ ### `behave_as_ar`
433
+
434
+ **Tramway Decorator** and **Tramway Form** support `behave_as_ar` method. It allows to use `update` and `destroy` methods with decorated and form objects.
435
+
424
436
  ## Contributing
425
437
 
426
438
  Install [lefthook](https://github.com/evilmartians/lefthook)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # desc "Explaining what the task does"
3
4
  # task :tramway do
4
5
  # # Task goes here
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'tramway/decorators/collection_decorator'
4
4
  require 'tramway/utils/render'
5
+ require 'tramway/duck_typing'
5
6
 
6
7
  module Tramway
7
8
  # Provides decorate function for Tramway projects
@@ -9,6 +10,7 @@ module Tramway
9
10
  class BaseDecorator
10
11
  include Tramway::Decorators::CollectionDecorators
11
12
  include Tramway::Utils::Render
13
+ include Tramway::DuckTyping::ActiveRecordCompatibility
12
14
 
13
15
  attr_reader :object
14
16
 
@@ -38,16 +40,10 @@ module Tramway
38
40
  end
39
41
  end
40
42
 
41
- delegate_attributes :id
42
-
43
43
  def to_partial_path
44
44
  underscored_class_name = object.class.name.underscore
45
45
 
46
46
  "#{underscored_class_name.pluralize}/#{underscored_class_name}"
47
47
  end
48
-
49
- def to_param
50
- id.to_s
51
- end
52
48
  end
53
49
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'tramway/forms/properties'
4
4
  require 'tramway/forms/normalizations'
5
+ require 'tramway/duck_typing'
5
6
 
6
7
  module Tramway
7
8
  # Provides form object for Tramway
@@ -9,13 +10,10 @@ module Tramway
9
10
  class BaseForm
10
11
  include Tramway::Forms::Properties
11
12
  include Tramway::Forms::Normalizations
13
+ include Tramway::DuckTyping::ActiveRecordCompatibility
12
14
 
13
15
  attr_reader :object
14
16
 
15
- %i[model_name to_key to_model errors attributes update destroy].each do |method_name|
16
- delegate method_name, to: :object
17
- end
18
-
19
17
  def initialize(object)
20
18
  @object = object
21
19
 
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tramway
4
+ module DuckTyping
5
+ # This module is used to make duck object compatible with ActiveRecord objects
6
+ module ActiveRecordCompatibility
7
+ # Contains behave_as_ar method
8
+ module ClassMethods
9
+ def behave_as_ar
10
+ %i[update update! destroy].each do |method_name|
11
+ delegate method_name, to: :object
12
+ end
13
+ end
14
+ end
15
+
16
+ %i[id model_name to_key errors to_param attributes].each do |method_name|
17
+ delegate method_name, to: :object
18
+ end
19
+
20
+ def self.included(base)
21
+ base.extend ClassMethods
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tramway/duck_typing/active_record_compatibility'
4
+
5
+ module Tramway
6
+ # This module is used to make duck object compatible
7
+ module DuckTyping
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.4.3'
4
+ VERSION = '0.4.4'
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.3
4
+ version: 0.4.4
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-03-05 00:00:00.000000000 Z
12
+ date: 2024-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-struct
@@ -124,6 +124,8 @@ files:
124
124
  - lib/tramway/configs/entity.rb
125
125
  - lib/tramway/decorators/class_helper.rb
126
126
  - lib/tramway/decorators/collection_decorator.rb
127
+ - lib/tramway/duck_typing.rb
128
+ - lib/tramway/duck_typing/active_record_compatibility.rb
127
129
  - lib/tramway/engine.rb
128
130
  - lib/tramway/forms/class_helper.rb
129
131
  - lib/tramway/forms/normalizations.rb