rlet 0.8.0 → 0.9.0
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 +61 -45
- data/lib/rlet/let.rb +4 -0
- data/lib/rlet/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb5e36d4acd8b61845d37ccfd308cd55a0303cc6
|
4
|
+
data.tar.gz: c88eedbf71546d8681a135195fa4fc066435efc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ac26acf602de92cc15bfe7dc9805d5b244d5811dc8baccf83f7f70b2eaa734894900c72f4fcef1d712e763a37129b651f8781c10503f8b389ad6fc544615fd2
|
7
|
+
data.tar.gz: 62c59a4e9fbf42060d96ee817472c6f04283b3a48cef29aedf8741a68f6abf2d40a400ad9e7aff937c1fe636e353873f95b78cb1fd4ef6fe7a95d2fca150a526
|
data/README.md
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# rlet
|
2
2
|
|
3
|
-
This library
|
4
|
-
|
3
|
+
This library provides RSpec-style let() declartions for lazy evaluation, concerns, and
|
4
|
+
a few functional operators.
|
5
5
|
|
6
|
-
Unlike ruby-let,
|
7
|
-
|
8
|
-
|
9
|
-
Here, `let()` defines a method in the class. The values are memoized. This allows for both
|
6
|
+
Unlike ruby-let, this does not actually mimic the let of functional programming. Here,
|
7
|
+
`let()` defines a method in the class. The values are memoized. This allows for both
|
10
8
|
lazy-evaluation and class-based scoping.
|
11
9
|
|
12
10
|
By defining methods for lazy evaluation and grouping them into concerns, you can create
|
@@ -31,17 +29,17 @@ The gems contain two modules, Let and Concern. You can use them like so:
|
|
31
29
|
class ContactsController
|
32
30
|
include Let
|
33
31
|
include RestfulResource
|
34
|
-
|
32
|
+
|
35
33
|
let(:model) { Contact }
|
36
|
-
|
34
|
+
|
37
35
|
def show
|
38
36
|
respond_with resource
|
39
37
|
end
|
40
38
|
end
|
41
|
-
|
39
|
+
|
42
40
|
module RestfulResource
|
43
41
|
extend Concern
|
44
|
-
|
42
|
+
|
45
43
|
included do
|
46
44
|
let(:resource) { model.find(id) }
|
47
45
|
let(:id) { params[:id] }
|
@@ -54,25 +52,43 @@ you want to use protected methods. You can do so with `letp`:
|
|
54
52
|
class ContactsController
|
55
53
|
include Let
|
56
54
|
include RestfulResource
|
57
|
-
|
55
|
+
|
58
56
|
letp(:model) { Contact }
|
59
|
-
|
57
|
+
|
60
58
|
def show
|
61
59
|
respond_with resource
|
62
60
|
end
|
63
61
|
end
|
64
|
-
|
62
|
+
|
65
63
|
module RestfulResource
|
66
64
|
extend Concern
|
67
|
-
|
65
|
+
|
68
66
|
included do
|
69
67
|
letp(:resource) { model.find(id) }
|
70
68
|
letp(:id) { params[:id] }
|
71
69
|
end
|
72
70
|
end
|
73
71
|
|
74
|
-
|
75
|
-
routes.
|
72
|
+
|
73
|
+
This is useful for Rails installation that still have dynamically inferred routes.
|
74
|
+
|
75
|
+
In Version 0.8.1+ both: let() and letp() return the name of the resource, there if you want to privatize let ruby 2.1+ you can do
|
76
|
+
|
77
|
+
class ContactsController
|
78
|
+
include Let
|
79
|
+
include RestfulResource
|
80
|
+
|
81
|
+
private let(:model) { Contact }
|
82
|
+
end
|
83
|
+
|
84
|
+
or in Rails, for the lazy
|
85
|
+
|
86
|
+
class ContactsController
|
87
|
+
include Let
|
88
|
+
include RestfulResource
|
89
|
+
|
90
|
+
helper_method letp(:model) { Contact }
|
91
|
+
end
|
76
92
|
|
77
93
|
Concern is embedded from ActiveSupport. If ActiveSupport::Concern is loaded, it will use that. This
|
78
94
|
allows one to use concerns without having ActiveSupport as a dependency.
|
@@ -81,24 +97,24 @@ Additionally, to expose `let()` with instance variables for use in templates, yo
|
|
81
97
|
|
82
98
|
require 'rlet'
|
83
99
|
require 'rlet/expose'
|
84
|
-
|
100
|
+
|
85
101
|
class ContactsController
|
86
102
|
include Let
|
87
103
|
include RLet::Expose
|
88
104
|
include RestfulResource
|
89
|
-
|
105
|
+
|
90
106
|
let(:model) { Contact }
|
91
107
|
|
92
108
|
expose :resource, only: :show
|
93
|
-
|
109
|
+
|
94
110
|
def show
|
95
111
|
respond_with resource
|
96
112
|
end
|
97
113
|
end
|
98
|
-
|
114
|
+
|
99
115
|
module RestfulResource
|
100
116
|
extend Concern
|
101
|
-
|
117
|
+
|
102
118
|
included do
|
103
119
|
let(:resource) { model.find(id) }
|
104
120
|
let(:id) { params[:id] }
|
@@ -118,15 +134,15 @@ For example:
|
|
118
134
|
class Promise
|
119
135
|
include Let
|
120
136
|
extend Intentions::Concerns::Register
|
121
|
-
|
137
|
+
|
122
138
|
attr_reader :identifier, :promiser, :promisee, :body, :metadata
|
123
|
-
|
139
|
+
|
124
140
|
let(:identifier) { Digest::SHA2.new.update(to_digest.inspect).to_s }
|
125
141
|
let(:sign) { metadata[:sign] }
|
126
142
|
let(:scope) { metadata[:scope] }
|
127
143
|
let(:timestamp) { Time.now.utc }
|
128
144
|
let(:salt) { rand(100000) }
|
129
|
-
|
145
|
+
|
130
146
|
def initialize(_promiser, _promisee, _body, _metadata = {})
|
131
147
|
@promiser = _promiser.freeze
|
132
148
|
@promisee = _promisee.freeze
|
@@ -134,11 +150,11 @@ For example:
|
|
134
150
|
@metadata = _metadata.freeze
|
135
151
|
self
|
136
152
|
end
|
137
|
-
|
153
|
+
|
138
154
|
def to_h
|
139
155
|
to_digest.merge(identifier: identifier)
|
140
156
|
end
|
141
|
-
|
157
|
+
|
142
158
|
def to_digest
|
143
159
|
{
|
144
160
|
promiser: promiser,
|
@@ -149,7 +165,7 @@ For example:
|
|
149
165
|
salt: salt
|
150
166
|
}
|
151
167
|
end
|
152
|
-
|
168
|
+
|
153
169
|
end
|
154
170
|
end
|
155
171
|
|
@@ -159,28 +175,28 @@ We can refactor into:
|
|
159
175
|
class Promise
|
160
176
|
include Let
|
161
177
|
extend Intentions::Concerns::Register
|
162
|
-
|
178
|
+
|
163
179
|
attr_reader :options
|
164
|
-
|
180
|
+
|
165
181
|
let(:promiser) { options[:promiser] }
|
166
182
|
let(:promisee) { options[:promisee] }
|
167
183
|
let(:body) { options[:body] }
|
168
184
|
let(:metadata) { options[:metadata] }
|
169
|
-
|
185
|
+
|
170
186
|
let(:identifier) { Digest::SHA2.new.update(to_digest.inspect).to_s }
|
171
187
|
let(:sign) { metadata[:sign] }
|
172
188
|
let(:scope) { metadata[:scope] }
|
173
189
|
let(:timestamp) { Time.now.utc }
|
174
190
|
let(:salt) { rand(100000) }
|
175
|
-
|
191
|
+
|
176
192
|
def initialize(_options = {})
|
177
193
|
@options = _options
|
178
194
|
end
|
179
|
-
|
195
|
+
|
180
196
|
def to_h
|
181
197
|
to_digest.merge(identifier: identifier)
|
182
198
|
end
|
183
|
-
|
199
|
+
|
184
200
|
def to_digest
|
185
201
|
{
|
186
202
|
promiser: promiser,
|
@@ -191,33 +207,33 @@ We can refactor into:
|
|
191
207
|
salt: salt
|
192
208
|
}
|
193
209
|
end
|
194
|
-
|
210
|
+
|
195
211
|
end
|
196
212
|
end
|
197
213
|
|
198
|
-
This pattern occurs so frequently that `rlet`
|
214
|
+
This pattern occurs so frequently that `rlet` now includes a `LazyOptions` concern.
|
199
215
|
|
200
216
|
module Intentions
|
201
217
|
class Promise
|
202
218
|
include Let
|
203
219
|
include RLet::LazyOptions
|
204
220
|
extend Intentions::Concerns::Register
|
205
|
-
|
221
|
+
|
206
222
|
let(:promiser) { options[:promiser] }
|
207
223
|
let(:promisee) { options[:promisee] }
|
208
224
|
let(:body) { options[:body] }
|
209
225
|
let(:metadata) { options[:metadata] }
|
210
|
-
|
226
|
+
|
211
227
|
let(:identifier) { Digest::SHA2.new.update(to_digest.inspect).to_s }
|
212
228
|
let(:sign) { metadata[:sign] }
|
213
229
|
let(:scope) { metadata[:scope] }
|
214
230
|
let(:timestamp) { Time.now.utc }
|
215
231
|
let(:salt) { rand(100000) }
|
216
|
-
|
232
|
+
|
217
233
|
def to_h
|
218
234
|
to_digest.merge(identifier: identifier)
|
219
235
|
end
|
220
|
-
|
236
|
+
|
221
237
|
def to_digest
|
222
238
|
{
|
223
239
|
promiser: promiser,
|
@@ -228,7 +244,7 @@ This pattern occurs so frequently that `rlet` not includes a `LazyOptions` conce
|
|
228
244
|
salt: salt
|
229
245
|
}
|
230
246
|
end
|
231
|
-
|
247
|
+
|
232
248
|
end
|
233
249
|
end
|
234
250
|
|
@@ -240,21 +256,21 @@ that adds in some operators.
|
|
240
256
|
|
241
257
|
Currently, only two are supported: `|` which composes right, and `*` which composes left.
|
242
258
|
|
243
|
-
The best example is when working with Intermodal presenters:
|
259
|
+
The best example is when working with [Intermodal](https://github.com/intermodal/intermodal) presenters:
|
244
260
|
|
245
261
|
require 'rlet/functional'
|
246
|
-
|
262
|
+
|
247
263
|
module SomeApi
|
248
264
|
module API
|
249
265
|
class V1_0 < Intermodal::API
|
250
266
|
using RLet::Functional
|
251
|
-
|
267
|
+
|
252
268
|
self.default_per_page = 25
|
253
|
-
|
269
|
+
|
254
270
|
map_data do
|
255
271
|
attribute = ->(field) { ->(r) { r.send(field) } }
|
256
272
|
helper = ->(_method) { ActionController::Base.helpers.method(_method) }
|
257
|
-
|
273
|
+
|
258
274
|
presentation_for :book do
|
259
275
|
presents :id
|
260
276
|
presents :price, with: attribute.(:price) | helper.(:number_to_currency)
|
data/lib/rlet/let.rb
CHANGED
data/lib/rlet/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rlet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ho-Sheng Hsiao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
59
|
version: 1.3.6
|
60
60
|
requirements: []
|
61
61
|
rubyforge_project: rlet
|
62
|
-
rubygems_version: 2.
|
62
|
+
rubygems_version: 2.5.2
|
63
63
|
signing_key:
|
64
64
|
specification_version: 4
|
65
65
|
summary: Lazy-eval and functional helpers
|