rack-component 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/rack/component.rb +14 -14
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 568c9eae25af8dd55cc2ac0b51c2b0da4de5818864c730c6f3965e3a4c92296b
4
- data.tar.gz: 25f0a6e450191a830bb08c06c5194fba2ec251e12c0586bf414d6994e386b04a
3
+ metadata.gz: a4a43f4454b5d988c4745d26c61bb46b8cbe21e56e3aa74d6b84427d4f110ab7
4
+ data.tar.gz: f49b907249aef3ebc79c5168c785eeb7ea977152c41278896e5cd4432467f2c5
5
5
  SHA512:
6
- metadata.gz: 123fdb85f98d1953993e2618369ce47a8d342e4346ab19d7a3322f4619cfbc4390145a3f39ecc46c70952b552fd61c636d98eb896926841224a0425ff2794adb
7
- data.tar.gz: b89ea9607fba5165632392d6878bd8272d1b07f4425c0498b89c6a28ad4260126cbcfed3213d2fd76d764343aabe124c0f43adeceba38254b20553b015465e55
6
+ metadata.gz: a48bcaf0c62f6d83071d6a99ce5517898d28d498dc8f23ef61392641ea7a71a6b921f8f65521f35c4c79a001c90978594a9d439f4e9ab67dc0094840b43cfafb
7
+ data.tar.gz: 87cd31cacc2c95b330e68cc07574f586c45777c69b0e4c5b6810fba0ff8325f4cb85b467fb718d35a201b3cbb7a09cf816c3ea7d2e05e5f0059d532c100e15be
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-component (0.1.0)
4
+ rack-component (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -4,7 +4,7 @@ module Rack
4
4
  # Subclass Rack::Component to compose declarative, component-based responses
5
5
  # to HTTP requests
6
6
  class Component
7
- VERSION = '0.1.0'.freeze
7
+ VERSION = '0.2.0'.freeze
8
8
 
9
9
  EMPTY = ''.freeze # components render an empty body by default
10
10
  attr_reader :props
@@ -17,22 +17,22 @@ module Rack
17
17
  # props[:world]
18
18
  # end
19
19
  #
20
- # def render
20
+ # def call
21
21
  # %(<h1>Hello #{world}</h1>)
22
22
  # end
23
23
  # end
24
24
  #
25
25
  # MyComponent.call(world: 'Earth') #=> '<h1>Hello Earth</h1>'
26
- # @return [String, Object] the rendered component instance
27
- def self.call(props = {}, &block)
28
- new(props).render(&block)
26
+ # @return [String, Object] the output of instance#render
27
+ def self.call(*props, &block)
28
+ new(*props).render(&block)
29
29
  end
30
30
 
31
31
  def initialize(props = {})
32
32
  @props = props
33
33
  end
34
34
 
35
- # Override render to make your component do work.
35
+ # Override call to make your component do work.
36
36
  # @return [String, Object] usually a string, but really whatever
37
37
  def render
38
38
  block_given? ? yield(self) : EMPTY
@@ -40,7 +40,7 @@ module Rack
40
40
 
41
41
  # Rack::Component::Memoized is just like Component, only it
42
42
  # caches its rendered output in memory and only rerenders
43
- # when called with new props or a new block.
43
+ # when called with new props.
44
44
  class Memoized < self
45
45
  CACHE_SIZE = 100 # limit cache to 100 keys by default so we don't leak RAM
46
46
 
@@ -57,7 +57,7 @@ module Rack
57
57
  # "#{props[:id]} was expensive"
58
58
  # end
59
59
  #
60
- # def render
60
+ # def call
61
61
  # %(<h1>#{work}</h1>)
62
62
  # end
63
63
  # end
@@ -70,25 +70,25 @@ module Rack
70
70
  # Expensive.call(id: 2) #=> <h1>2 was expensive</h1>
71
71
  #
72
72
  # @return [String, Object] the cached (or computed) output of render
73
- def self.call(props = {}, &block)
74
- memoized(props) { super }
73
+ def self.call(*props, &block)
74
+ memoized(*props) { super }
75
75
  end
76
76
 
77
77
  # Check the class-level cache, set it to &miss if nil.
78
78
  # @return [Object] the output of &miss.call
79
- def self.memoized(props, &miss)
80
- cache.fetch(key(props), &miss)
79
+ def self.memoized(*props, &miss)
80
+ cache.fetch(key(*props), &miss)
81
81
  end
82
82
 
83
83
  # @return [Integer] a cache key for this component
84
- def self.key(props)
84
+ def self.key(*props)
85
85
  props.hash
86
86
  end
87
87
 
88
88
  # Clear the cache of each descendant class.
89
89
  # Generally you'll call this on Rack::Component::Memoized directly.
90
90
  # @example Clear all caches:
91
- # Rack::Component::Memoized.flush_caches
91
+ # Rack::Component::Memoized.clear_caches
92
92
  def self.clear_caches
93
93
  ObjectSpace.each_object(singleton_class) do |descendant|
94
94
  descendant.cache.flush
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-12 00:00:00.000000000 Z
11
+ date: 2018-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips