presentability 0.1.0.pre.20220808082516 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -0
- data/History.md +5 -1
- data/README.md +4 -9
- data/lib/presentability/presenter.rb +50 -14
- data/lib/presentability.rb +61 -2
- data.tar.gz.sig +4 -0
- metadata +33 -8
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b10ef3f8fba6959cfd51db2efee95b4df669863b1ef433656da03573d61f07
|
4
|
+
data.tar.gz: beefa821c8f69d2038a992d4064b08429202100a6a9b139bc4427247f31f47c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b2974973651bc54624dbca03bd89d841dd4aab00dcdc72f38ada1a40bb626b7096d78c2fd917b31c45af99d5771d0d935ce751da473ec8ef93e9dff2b01876d
|
7
|
+
data.tar.gz: 874444891db074bd26600f61bdacea937b75553616e541c6b50f0c69f0e888c2c5f437895da5d4bb5df5ca0dec849f73848f27230076e8883aec1ef30378393b
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
:���Ҥ��7F�1/ІY��Ӝv�5�&�i�����F�(���Z�2&�QY���^���x�E��d}�æi��@�!o]�Hǖ(�ö�������"0*��!��P�H�ʸ˃ዎ��J������5��}���?ҮJ��"7HA�g}����JO�A�����$�?<(���!N|�F{0i#��0�qٍ,�I�%�_�AՆ,M�Jϥ��l튞3�%6 uwCXm
|
2
|
+
�We�>��7�8��ڽ�D�˄�rcWϲ̱clO��\h���E�7�ܓ���"uq�p�gL����SN>*�<�S�Z��zT8�i�x�`�d�{��ܓH-�2����;UE�8z��b�r>vR�rda��IT�#��N����`�H/
|
data/History.md
CHANGED
data/README.md
CHANGED
@@ -22,14 +22,9 @@ services, logging output, etc.
|
|
22
22
|
It is intended to be dead-simple by default, returning a Hash containing
|
23
23
|
only the attributes you have intentionally exposed from the subject.
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
:name,
|
29
|
-
:unit_price,
|
30
|
-
:internal_cost,
|
31
|
-
:inventory_count
|
32
|
-
end
|
25
|
+
The most basic usage looks something like this:
|
26
|
+
|
27
|
+
require 'presentatbility'
|
33
28
|
|
34
29
|
# lib/acme/presenters.rb
|
35
30
|
module Acme::Presenters
|
@@ -45,7 +40,7 @@ only the attributes you have intentionally exposed from the subject.
|
|
45
40
|
# lib/acme/service.rb
|
46
41
|
class Acme::Service < Some::Webservice::Framework
|
47
42
|
|
48
|
-
|
43
|
+
get '/api/widgets/<sku>' do |sku|
|
49
44
|
widget = Acme::Widget.lookup( sku )
|
50
45
|
content_type 'application/json'
|
51
46
|
representation = Acme::Presenters.present( widget )
|
@@ -5,7 +5,39 @@ require 'loggability'
|
|
5
5
|
|
6
6
|
require 'presentability' unless defined?( Presentability )
|
7
7
|
|
8
|
-
|
8
|
+
#
|
9
|
+
# A presenter (facade) base class.
|
10
|
+
#
|
11
|
+
# When you declare a presenter in a Presentability collection, the result is a
|
12
|
+
# subclass of Presentability::Presenter. The main way of defining a Presenter's
|
13
|
+
# functionality is via the ::expose method, which marks an attribute of the underlying
|
14
|
+
# entity object (the "subject") for exposure.
|
15
|
+
#
|
16
|
+
# ```ruby
|
17
|
+
# class MyPresenter < Presentability::Presenter
|
18
|
+
# expose :name
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# # Assuming `entity_object' has a "name" attribute...
|
22
|
+
# presenter = MyPresenter.new( entity_object )
|
23
|
+
# presenter.apply
|
24
|
+
# # => { :name => "entity name" }
|
25
|
+
# ```
|
26
|
+
#
|
27
|
+
# Setting up classes like this manually is one option, but Presentability also lets you
|
28
|
+
# set them up as a collection, which is what further examples will assume for brevity:
|
29
|
+
#
|
30
|
+
# ```ruby
|
31
|
+
# module MyPresenters
|
32
|
+
# extend Presentability
|
33
|
+
#
|
34
|
+
# presenter_for( EntityObject ) do
|
35
|
+
# expose :name
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# end
|
39
|
+
# ```
|
40
|
+
#
|
9
41
|
class Presentability::Presenter
|
10
42
|
extend Loggability
|
11
43
|
|
@@ -66,13 +98,6 @@ class Presentability::Presenter
|
|
66
98
|
attr_reader :options
|
67
99
|
|
68
100
|
|
69
|
-
### Return a new instance of whatever object type will be used to represent the
|
70
|
-
### subject.
|
71
|
-
def empty_representation
|
72
|
-
return {}
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
101
|
### Apply the exposures to the subject and return the result.
|
77
102
|
def apply
|
78
103
|
result = self.empty_representation
|
@@ -101,6 +126,23 @@ class Presentability::Presenter
|
|
101
126
|
end
|
102
127
|
|
103
128
|
|
129
|
+
### Return a human-readable representation of the object suitable for debugging.
|
130
|
+
def inspect
|
131
|
+
return "#<Presentability::Presenter:%#0x for %p>" % [ self.object_id / 2, self.subject ]
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
#########
|
136
|
+
protected
|
137
|
+
#########
|
138
|
+
|
139
|
+
### Return a new instance of whatever object type will be used to represent the
|
140
|
+
### subject.
|
141
|
+
def empty_representation
|
142
|
+
return {}
|
143
|
+
end
|
144
|
+
|
145
|
+
|
104
146
|
### Attempt to expose the attribute with the given +name+ via delegation to the
|
105
147
|
### subject's method of the same name. Returns +nil+ if no such method exists.
|
106
148
|
def expose_via_delegation( name, options={} )
|
@@ -123,11 +165,5 @@ class Presentability::Presenter
|
|
123
165
|
return meth.call
|
124
166
|
end
|
125
167
|
|
126
|
-
|
127
|
-
### Return a human-readable representation of the object suitable for debugging.
|
128
|
-
def inspect
|
129
|
-
return "#<Presentability::Presenter:%#0x for %p>" % [ self.object_id / 2, self.subject ]
|
130
|
-
end
|
131
|
-
|
132
168
|
end # class Presentability::Presenter
|
133
169
|
|
data/lib/presentability.rb
CHANGED
@@ -4,13 +4,68 @@
|
|
4
4
|
require 'loggability'
|
5
5
|
|
6
6
|
|
7
|
-
# Facade-based
|
7
|
+
# Facade-based presenter toolkit with minimal assumptions.
|
8
|
+
#
|
9
|
+
# ## Basic Usage
|
10
|
+
#
|
11
|
+
# Basic usage of Presentability requires two steps: declaring presenters and
|
12
|
+
# then using them.
|
13
|
+
#
|
14
|
+
# ### Declaring Presenters
|
15
|
+
#
|
16
|
+
# Presenters are just regular Ruby classes with some convenience methods for
|
17
|
+
# declaring exposures, but in a lot of cases you'll want to declare them all in
|
18
|
+
# one place. Presentability offers a mixin that implements a simple DSL for
|
19
|
+
# declaring presenters and their associations to entity classes, intended to be
|
20
|
+
# used in a container module:
|
21
|
+
#
|
22
|
+
# ```ruby
|
23
|
+
# require 'presentability'
|
24
|
+
#
|
25
|
+
# module Acme::Presenters
|
26
|
+
# extend Presentability
|
27
|
+
#
|
28
|
+
# presenter_for( Acme::Widget ) do
|
29
|
+
# expose :sku
|
30
|
+
# expose :name
|
31
|
+
# expose :unit_price
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# end
|
35
|
+
# ```
|
36
|
+
#
|
37
|
+
# The block of `presenter_for` is evaluated in the context of a new Presenter
|
38
|
+
# class, so refer to that documentation for what's possible there.
|
39
|
+
#
|
40
|
+
# Sometimes you can't (or don't want to) have to load the entity class to
|
41
|
+
# declare a presenter for it, so you can also declare it using the class's name:
|
42
|
+
#
|
43
|
+
# ```ruby
|
44
|
+
# presenter_for( 'Acme::Widget' ) do
|
45
|
+
# expose :sku
|
46
|
+
# expose :name
|
47
|
+
# expose :unit_price
|
48
|
+
# end
|
49
|
+
# ```
|
50
|
+
#
|
51
|
+
# ### Using Presenters
|
52
|
+
#
|
53
|
+
# You use presenters by instantiating them with the object they are a facade for
|
54
|
+
# (the "subject"), and then applying it:
|
55
|
+
#
|
56
|
+
# ```ruby
|
57
|
+
# presenter = Acme::Presenters.present( acme_widget )
|
58
|
+
# presenter.apply
|
59
|
+
# # => { :sku => "FF-2237H455", :name => "Throbbing Frobnulator", :unit_price => 299 }
|
60
|
+
# ```
|
61
|
+
#
|
62
|
+
#
|
8
63
|
module Presentability
|
9
64
|
extend Loggability
|
10
65
|
|
11
66
|
|
12
67
|
# Package version
|
13
|
-
VERSION = '0.0
|
68
|
+
VERSION = '0.1.0'
|
14
69
|
|
15
70
|
|
16
71
|
# Automatically load subordinate components
|
@@ -49,6 +104,10 @@ module Presentability
|
|
49
104
|
end
|
50
105
|
|
51
106
|
|
107
|
+
#########
|
108
|
+
protected
|
109
|
+
#########
|
110
|
+
|
52
111
|
### Return a representation of the +object+ by applying a presenter declared for its
|
53
112
|
### class. Returns +nil+ if no such presenter exists.
|
54
113
|
def present_by_class( object, **presentation_options )
|
data.tar.gz.sig
ADDED
metadata
CHANGED
@@ -1,14 +1,39 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: presentability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIID+DCCAmCgAwIBAgIBBDANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
|
14
|
+
REM9RmFlcmllTVVEL0RDPW9yZzAeFw0yMjAxMDcyMzU4MTRaFw0yMzAxMDcyMzU4
|
15
|
+
MTRaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
|
16
|
+
hkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAvyVhkRzvlEs0fe7145BYLfN6njX9ih5H
|
17
|
+
L60U0p0euIurpv84op9CNKF9tx+1WKwyQvQP7qFGuZxkSUuWcP/sFhDXL1lWUuIl
|
18
|
+
M4uHbGCRmO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33
|
+
P5YP5BAbNW+gvd3QHRiWTTuhgHrdDnGdXg93N2M5KHn1ug8BtPLQwlcFwEpKnlLn
|
34
|
+
btEP+7EplFuoiMfd
|
35
|
+
-----END CERTIFICATE-----
|
36
|
+
date: 2022-08-11 00:00:00.000000000 Z
|
12
37
|
dependencies:
|
13
38
|
- !ruby/object:Gem::Dependency
|
14
39
|
name: loggability
|
@@ -73,11 +98,11 @@ homepage: https://hg.sr.ht/~ged/Presentability
|
|
73
98
|
licenses:
|
74
99
|
- BSD-3-Clause
|
75
100
|
metadata:
|
76
|
-
bug_tracker_uri: https://todo.sr.ht/~ged/Presentability
|
77
|
-
changelog_uri: https://deveiate.org/code/presentability/History_md.html
|
78
|
-
documentation_uri: https://deveiate.org/code/presentability
|
79
101
|
homepage_uri: https://hg.sr.ht/~ged/Presentability
|
102
|
+
documentation_uri: https://deveiate.org/code/presentability
|
103
|
+
changelog_uri: https://deveiate.org/code/presentability/History_md.html
|
80
104
|
source_uri: https://hg.sr.ht/~ged/Presentability
|
105
|
+
bug_tracker_uri: https://todo.sr.ht/~ged/Presentability
|
81
106
|
post_install_message:
|
82
107
|
rdoc_options: []
|
83
108
|
require_paths:
|
@@ -89,9 +114,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
114
|
version: '0'
|
90
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
116
|
requirements:
|
92
|
-
- - "
|
117
|
+
- - ">="
|
93
118
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
119
|
+
version: '0'
|
95
120
|
requirements: []
|
96
121
|
rubygems_version: 3.3.7
|
97
122
|
signing_key:
|
metadata.gz.sig
ADDED
Binary file
|