presentability 0.1.0.pre.20220808082516 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 804aef5ae0367b75c4182c98315ad2791419fde213551ea9a5d9e860849b3e44
4
- data.tar.gz: be7e218aafbbeb7f743d612da6498ab0b8a841594ca704fe342c2df2751bf1ec
3
+ metadata.gz: c0b10ef3f8fba6959cfd51db2efee95b4df669863b1ef433656da03573d61f07
4
+ data.tar.gz: beefa821c8f69d2038a992d4064b08429202100a6a9b139bc4427247f31f47c1
5
5
  SHA512:
6
- metadata.gz: e461283d2b5c43af73319f41277b870b57372329a3194c2b37609a4a537493dfe12bf59be44d9da83a491957eb7f965430e0c670697d1058abb43cd30d4c2564
7
- data.tar.gz: ba92018b64fe673aa858d1fc47381d43c11a0f5fe27bb640a9a44bf5f9f194fc2791f0faad3358fb44b9334dfe587bb9a49f461ad8fed6c11eb8d4cf96920635
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
@@ -1,4 +1,8 @@
1
- ## v0.0.1 [YYYY-MM-DD] Michael Granger <ged@FaerieMUD.org>
1
+ # Release History for presentability
2
+
3
+ ---
4
+
5
+ ## v0.1.0 [2022-08-11] Michael Granger <ged@faeriemud.org>
2
6
 
3
7
  Initial release.
4
8
 
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
- # lib/acme/widget.rb
26
- class Acme::Widget
27
- attr_accessor :sku,
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
- on '/api/widgets/<sku>' do |sku|
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
 
@@ -4,13 +4,68 @@
4
4
  require 'loggability'
5
5
 
6
6
 
7
- # Facade-based presenters with minimal assumptions.
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.1'
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
@@ -0,0 +1,4 @@
1
+ �s�k��z�u]%��0v�^9��S9��o%��Ǘ��= �l;�D+Ke��遽Dv�M��z$����H�"���-7��>��K�
2
+ �!���PI��(B���>2N2����!�H�b|L�;_�L3q/�I��3���ӓ��Z����>�"�D�L5�����^��3��6ޑ#g�*}i5�����B}���gr�W“����|4`}ym#˖D��yU��O��r��S�c�޴V��>@37a������X@뽧�}����J���
3
+ n�f
4
+ �d���;yX
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.pre.20220808082516
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
- date: 2022-08-08 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIID+DCCAmCgAwIBAgIBBDANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
14
+ REM9RmFlcmllTVVEL0RDPW9yZzAeFw0yMjAxMDcyMzU4MTRaFw0yMzAxMDcyMzU4
15
+ MTRaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
16
+ hkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAvyVhkRzvlEs0fe7145BYLfN6njX9ih5H
17
+ L60U0p0euIurpv84op9CNKF9tx+1WKwyQvQP7qFGuZxkSUuWcP/sFhDXL1lWUuIl
18
+ M4uHbGCRmOshDrF4dgnBeOvkHr1fIhPlJm5FO+Vew8tSQmlDsosxLUx+VB7DrVFO
19
+ 5PU2AEbf04GGSrmqADGWXeaslaoRdb1fu/0M5qfPTRn5V39sWD9umuDAF9qqil/x
20
+ Sl6phTvgBrG8GExHbNZpLARd3xrBYLEFsX7RvBn2UPfgsrtvpdXjsHGfpT3IPN+B
21
+ vQ66lts4alKC69TE5cuKasWBm+16A4aEe3XdZBRNmtOu/g81gvwA7fkJHKllJuaI
22
+ dXzdHqq+zbGZVSQ7pRYHYomD0IiDe1DbIouFnPWmagaBnGHwXkDT2bKKP+s2v21m
23
+ ozilJg4aar2okb/RA6VS87o+d7g6LpDDMMQjH4G9OPnJENLdhu8KnPw/ivSVvQw7
24
+ N2I4L/ZOIe2DIVuYH7aLHfjZDQv/mNgpAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYD
25
+ VR0PBAQDAgSwMB0GA1UdDgQWBBRyjf55EbrHagiRLqt5YAd3yb8k4DANBgkqhkiG
26
+ 9w0BAQsFAAOCAYEASrm1AbEoxACZ9WXJH3R5axV3U0CA4xaETlL2YT+2nOfVBMQ9
27
+ 0ZlkPx6j4ghKJgAIi1TMfDM2JyPJsppQh8tiNccDjWc62UZRY/dq26cMqf/lcI+a
28
+ 6YBuEYvzZfearwVs8tHnXtwYV3WSCoCOQaB+nq2lA1O+nkKNl41WOsVbNama5jx3
29
+ 8cQtVSEEmZy6jIDJ8c5TmBJ7BQUDEUEWA/A3V42Xyctoj7DvUXWE0lP+X6ypAVSr
30
+ lFh3TS64D7NTvxkmg7natUoCvobl6kGl4yMaqE4YRTlfuzhpf91TSOntClqrAOsS
31
+ K1s56WndQj3IoBocdY9mQhDZLtLHofSkymoP8btBlj5SsN24TiF0VMSZlctSCYZg
32
+ GKyHim/MMlIfGOWsgfioq5jzwmql7W4CDubbb8Lkg70v+hN2E/MnNVAcNE3gyaGc
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: 1.3.1
119
+ version: '0'
95
120
  requirements: []
96
121
  rubygems_version: 3.3.7
97
122
  signing_key:
metadata.gz.sig ADDED
Binary file