turbo_live 0.2.1 → 0.3.0

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: f8bb20b23ebd77936e9d016fc914bad406118d259fc7e21b814ab21bd162dd48
4
- data.tar.gz: b34976b5f6b8ba0e48a51f26d7fee4f13c2870631c5fdab88860e16db49d9bb0
3
+ metadata.gz: f35b2977f8f91c94aa92547a23facedec57a0fe96c10b497a9ee4f0583ee3aa6
4
+ data.tar.gz: b2d82cbcc93d640fd1dee6a32753fe93d5ef7e509e2e6db569d74b24c84cb651
5
5
  SHA512:
6
- metadata.gz: f23e8d630a733dad9c92b6ad79458213aa97b0f7f1c527a1e30b4b65914e62675ffeda07e3a272cdd8e8d924500c8fe36ae16c712922788b50b4939bcedad464
7
- data.tar.gz: 266d2bcc3e8b82977ee5474dee219b88ce3e0d82b6de7258f231ec302807e87b8479422b4c124a8b3c05d1792d4293e01d81460b66809b1dfa7d4ea969b7923b
6
+ metadata.gz: 3108716f45050495efcb80b7c5d7b8ea0ba0fe1712ffa72165299dc31ad9e0a7443e3e961323ed33dbcb35f4fb4f65c52d1a530f5b2e8e537028d7fec612f91a
7
+ data.tar.gz: 1118bcb7d3bcbd573265edaff2be2b3d5590614a7018d68e8ecb4e628404c6eec24f4ce00d1f6260ecf078e717d6ff8741e1dbc603389395b22eb4539971d541
data/README.md CHANGED
@@ -6,6 +6,10 @@ TurboLive is a Ruby gem that enables the creation of async, progressively enhanc
6
6
 
7
7
  - [Installation](#installation)
8
8
  - [Setup](#setup)
9
+ - [Rails Routes](#rails-routes)
10
+ - [Stimulus Controller](#stimulus-controller)
11
+ - [ActionCable (Optional)](#actioncable-optional)
12
+ - [Serializer Configuration](#serializer-configuration)
9
13
  - [Usage](#usage)
10
14
  - [Creating a Component](#creating-a-component)
11
15
  - [Model State](#model-state)
@@ -110,6 +114,28 @@ import "controllers"
110
114
  +import "channels"
111
115
  ```
112
116
 
117
+ ### Serializer Configuration
118
+
119
+ TurboLive requires a serializer for state management.
120
+
121
+ The default serializer (`TurboLive::Serializer`) simply wraps YAML, which handles primitive objects and basic collections.
122
+ If you need to serialize complex objects, you can provide your own serializer implementation or customize the in-built.
123
+
124
+ You can configure the serializer in an initializer:
125
+
126
+ ```ruby
127
+ # config/initializers/turbo_live.rb
128
+
129
+ # Optional - defaults to TurboLive::Serializer
130
+ TurboLive.serializer = YourCustomSerializer
131
+
132
+ # (Optional) You can set a custom verifier key for security
133
+ TurboLive.verifier_key = Rails.application.secret_key_base
134
+
135
+ # pass extra permitted classes to the underlying YAML serializer
136
+ TurboLive::Serializer.permitted_classes << BigDecimal
137
+ ```
138
+
113
139
  ## Usage
114
140
 
115
141
  A TurboLive component is a self-contained, interactive unit of a web application that can update in real-time without full page reloads. Components follow [The Elm Architecture](https://guide.elm-lang.org/architecture/) pattern.
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TurboLive
4
+ class Serializer
5
+ class << self
6
+ def dump(obj)
7
+ YAML.dump(obj)
8
+ end
9
+
10
+ def load(obj)
11
+ YAML.safe_load(obj, permitted_classes: permitted_classes)
12
+ end
13
+
14
+ def permitted_classes
15
+ @permitted_classes ||= []
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TurboLive
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/turbo_live.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "turbo_live/version"
4
4
  require_relative "turbo_live/component"
5
5
  require_relative "turbo_live/renderer"
6
+ require_relative "turbo_live/serializer"
6
7
 
7
8
  require_relative "turbo_live/engine" if defined?(Rails)
8
9
  require_relative "../app/channels/turbo_live/components_channel" if defined?(ActionCable::Channel::Base)
@@ -17,13 +18,18 @@ module TurboLive
17
18
 
18
19
  class << self
19
20
  attr_writer :verifier_key
21
+ attr_writer :serializer
20
22
 
21
23
  def verifier
22
- @verifier ||= ActiveSupport::MessageVerifier.new(verifier_key, digest: "SHA256", serializer: YAML)
24
+ @verifier ||= ActiveSupport::MessageVerifier.new(verifier_key, digest: "SHA256", serializer: serializer)
23
25
  end
24
26
 
25
27
  def verifier_key
26
28
  @verifier_key or raise ArgumentError, "Turbo requires a verifier_key"
27
29
  end
30
+
31
+ def serializer
32
+ @serializer ||= TurboLive::Serializer
33
+ end
28
34
  end
29
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_live
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheDumbTechGuy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-23 00:00:00.000000000 Z
11
+ date: 2024-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex-rails
@@ -64,6 +64,7 @@ files:
64
64
  - lib/turbo_live/component.rb
65
65
  - lib/turbo_live/engine.rb
66
66
  - lib/turbo_live/renderer.rb
67
+ - lib/turbo_live/serializer.rb
67
68
  - lib/turbo_live/version.rb
68
69
  - package-lock.json
69
70
  - package.json