lazy_value 0.0.2 → 0.0.3

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: 39c7e1e0a2dc4c49d36a057f49ffb054a527ae09880e8967067e4ce5b864e2b5
4
- data.tar.gz: ad44eab22f9afcd3198a957cc41f0f810d43066b7e1b3b6fcbef3da1981d837d
3
+ metadata.gz: ff43403a1c22e54f42ccc10e23553ca1185da22aa520bd19239863da25be47fe
4
+ data.tar.gz: 38e5f11b43ff1b07d08df7f4e1530ce86f967d5ec51c6af7601414f0d3d41c25
5
5
  SHA512:
6
- metadata.gz: 32e9bdc1463df76ecd671811f876cfacd1d3961275f8506a6ca9b0fdfdd68a0fd2774b3d078a951d67ff8050216587712e2843955761e06f7eed31a7f4d51189
7
- data.tar.gz: 5594961af3dbfb7b83f3266024f2c92e031ccd3c84973f27e015e1ce805febec3970e79ea09b7de1ef59964bded77791cb2fac7581a1af3b6b08ff4c04f6397f
6
+ metadata.gz: 64c8b7a444814282cfaf80acb512405f2194b7f18dd388104e4ff3fcff601eb1dfd891d82d296571fd33b3121f8ab58f4322583bf741089f1d282747b2e5cb3a
7
+ data.tar.gz: 3d90984bba75aced80822d571450179b59580a4f3bf8764973a966de332a590062f0501a13a610d596e4e6b808d0b8dad838817d337f6750b85dfd9d74676f5d
data/README.md CHANGED
@@ -25,6 +25,17 @@ Functioning similarly to lazy Turbo frames, this value loader has no reliance on
25
25
 
26
26
  ## Usage
27
27
 
28
+ It's strongly suggested to configure initializer (can be generated with `rails g lazy_value initializer`). You can put your credentials/secrets/env variable. It's needed to use the same encryption key between deploys or server instances.
29
+
30
+ ```ruby
31
+ LazyValue.setup do |config|
32
+ config.salt = ENV["LAZY_VALUE_SALT"].presence || SecureRandom.random_bytes(ActiveSupport::MessageEncryptor.key_len)
33
+ config.key = ENV["LAZY_VALUE_KEY"].presence || SecureRandom.hex(32)
34
+ end
35
+ ```
36
+
37
+ And now you can use `lazy_value_tag` helper in your views:
38
+
28
39
  ```erb
29
40
  <div class="column is-one-quarter">
30
41
  <div class="box has-text-centered">
@@ -99,6 +110,13 @@ And that is it. Start using it.
99
110
 
100
111
  `bin/rails test:system`.
101
112
 
113
+ ## TODO
114
+
115
+ - websockets options vs http
116
+ - pass variables
117
+ - change to modern JS?
118
+ - use POST? (if payload might be too big)
119
+
102
120
  ## Contributing
103
121
 
104
122
  You are welcome to contribute.
@@ -109,4 +127,3 @@ The gem is available as open source under the terms of the [MIT License](https:/
109
127
 
110
128
  [<img src="https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/more_gems.png?raw=true"
111
129
  />](https://www.railsjazz.com/?utm_source=github&utm_medium=bottom&utm_campaign=rails_live_reload)
112
-
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generate configuration file.
3
+
4
+ Example:
5
+ rails generate lazy_value initializer
6
+
7
+ This will create:
8
+ config/lazy_value.rb
@@ -0,0 +1,6 @@
1
+ class LazyValueGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ def copy_initializer
4
+ template 'template.rb', 'config/initializers/lazy_value.rb'
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ LazyValue.setup do |config|
2
+ config.key = ENV["LAZY_VALUE_KEY"]
3
+ config.salt = ENV["LAZY_VALUE_SALT"]
4
+ end
@@ -1,3 +1,3 @@
1
1
  module LazyValue
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/lazy_value.rb CHANGED
@@ -3,13 +3,28 @@ require "lazy_value/routes"
3
3
  require "lazy_value/engine"
4
4
 
5
5
  module LazyValue
6
- mattr_accessor :cryptography
6
+ mattr_accessor :key
7
+ @@key = ENV["LAZY_VALUE_KEY"].presence || SecureRandom.hex(32)
7
8
 
8
- @@cryptography = begin
9
- len = ActiveSupport::MessageEncryptor.key_len
10
- salt = SecureRandom.random_bytes(len)
11
- key = ActiveSupport::KeyGenerator.new(SecureRandom.hex(32)).generate_key(salt, len)
12
- ActiveSupport::MessageEncryptor.new(key)
9
+ mattr_accessor :salt
10
+ @@salt = ENV["LAZY_VALUE_SALT"].presence || SecureRandom.hex(8)
11
+
12
+ def self.setup
13
+ yield(self)
14
+ end
15
+
16
+ def self.cryptography
17
+ @cryptography ||= begin
18
+ ActiveSupport::MessageEncryptor.new(derived_key)
19
+ end
20
+ end
21
+
22
+ def self.derived_key
23
+ key_generator.generate_key(salt, 32)
24
+ end
25
+
26
+ def self.key_generator
27
+ ActiveSupport::KeyGenerator.new(key, iterations: 1000)
13
28
  end
14
29
 
15
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_value
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-16 00:00:00.000000000 Z
12
+ date: 2023-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -137,6 +137,9 @@ files:
137
137
  - app/controllers/lazy_value/application_controller.rb
138
138
  - app/helpers/lazy_value/application_helper.rb
139
139
  - config/routes.rb
140
+ - lib/generators/lazy_value/USAGE
141
+ - lib/generators/lazy_value/lazy_value_generator.rb
142
+ - lib/generators/lazy_value/templates/template.rb
140
143
  - lib/lazy_value.rb
141
144
  - lib/lazy_value/engine.rb
142
145
  - lib/lazy_value/railtie.rb