exposant 0.1.0 → 0.1.2
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/Gemfile.lock +6 -6
- data/README.md +53 -3
- data/Rakefile +1 -1
- data/lib/exposant/collection_exhibitor.rb +6 -1
- data/lib/exposant/concerns/exhibitor.rb +10 -0
- data/lib/exposant/concerns/{presentable.rb → exposable.rb} +2 -2
- data/lib/exposant/version.rb +1 -1
- data/lib/exposant.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e71f97dbf32080d25a520091a6e33d480ad18e6a3fff6bcd6e450b80c0cd5414
|
4
|
+
data.tar.gz: 499db0ccd9fd33e879dcc035f4decf21ea7c8874042ddc113bc4862b3bf726e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d446462784d85f9b13426e79fb69a484a827c8bb347d117c286fa3da0a841aace9c51ea265a5d23256a53da36112c6b3b6c28be0a6502a28cb1c7414bd80a2e7
|
7
|
+
data.tar.gz: 4f0642a4b7001c14b149deaf738738ae13e8541cb54c3987405e383ef5656c1ade8fe84c1b8c31756659c7816869c10b0a83023f18500ac73c81d2560d733ed6
|
data/Gemfile.lock
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
exposant (0.1.
|
4
|
+
exposant (0.1.2)
|
5
5
|
activemodel (~> 7.0)
|
6
6
|
activesupport (~> 7.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (7.0.4)
|
12
|
-
activesupport (= 7.0.4)
|
13
|
-
activesupport (7.0.4)
|
11
|
+
activemodel (7.0.4.2)
|
12
|
+
activesupport (= 7.0.4.2)
|
13
|
+
activesupport (7.0.4.2)
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
15
|
i18n (>= 1.6, < 2)
|
16
16
|
minitest (>= 5.1)
|
17
17
|
tzinfo (~> 2.0)
|
18
18
|
ast (2.4.2)
|
19
|
-
concurrent-ruby (1.
|
19
|
+
concurrent-ruby (1.2.0)
|
20
20
|
i18n (1.12.0)
|
21
21
|
concurrent-ruby (~> 1.0)
|
22
22
|
json (2.6.1)
|
@@ -41,7 +41,7 @@ GEM
|
|
41
41
|
rubocop-ast (1.21.0)
|
42
42
|
parser (>= 3.1.1.0)
|
43
43
|
ruby-progressbar (1.11.0)
|
44
|
-
tzinfo (2.0.
|
44
|
+
tzinfo (2.0.6)
|
45
45
|
concurrent-ruby (~> 1.0)
|
46
46
|
unicode-display_width (2.2.0)
|
47
47
|
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Exposant
|
2
2
|
|
3
|
-
|
3
|
+
In a Rails application, it is often required to fill a gap between Models and
|
4
|
+
Views. There are of course, many differents ways to fill this gap, one of these
|
5
|
+
is exhibitors (or improved decorators).
|
4
6
|
|
5
|
-
|
7
|
+
This gem provide an easy way to create Ruby exhibitors or decorators.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -22,7 +24,55 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
There are two kinds of exhibitors refering to model or collection.
|
28
|
+
|
29
|
+
A collection exhibitor is meant to encapsulate an enumerable object (like
|
30
|
+
ActiveRecord Relation or just Array). It overrides `each` method to ensure
|
31
|
+
encapsulation of resulting objects.
|
32
|
+
|
33
|
+
A model exhibitor improve it's associated object, like adding non-database
|
34
|
+
related methods to an ActiveRecord object for example.
|
35
|
+
|
36
|
+
To use this gem in a Rails application, create a folder `app/exhibitors`.
|
37
|
+
Create pluralized exhibitors for collections and singularized exhibitors for
|
38
|
+
models.
|
39
|
+
|
40
|
+
### Example:
|
41
|
+
|
42
|
+
Consider having a User model with `first_name` and `last_name`
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# app/models/application_record.rb
|
46
|
+
class ApplicationRecord < ActiveRecord::Base
|
47
|
+
include Exposant::Exposable
|
48
|
+
end
|
49
|
+
|
50
|
+
# app/exhibitors/user_exhibitor.rb
|
51
|
+
class UserExhibitor < Exposant::ModelExhibitor
|
52
|
+
def full_name
|
53
|
+
"#{first_name} #{last_name}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# app/exhibitors/users_exhibitor.rb
|
58
|
+
class UsersExhibitor < Exposant::CollectionExhibitor
|
59
|
+
# You can add methods for collections too if necessary
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
Then you may want to use your brand new exhibitor in your controller
|
64
|
+
```ruby
|
65
|
+
# app/controllers/users_controller.rb
|
66
|
+
class UsersController < DefaultController
|
67
|
+
def index
|
68
|
+
@users = User.exhibitor(User.all)
|
69
|
+
end
|
70
|
+
|
71
|
+
def show
|
72
|
+
@user = User.find(...).exhibitor
|
73
|
+
end
|
74
|
+
end
|
75
|
+
```
|
26
76
|
|
27
77
|
## Development
|
28
78
|
|
data/Rakefile
CHANGED
@@ -11,7 +11,12 @@ module Exposant
|
|
11
11
|
def each
|
12
12
|
return enum_for(:each) unless block_given?
|
13
13
|
|
14
|
-
__getobj__.each
|
14
|
+
__getobj__.each do |o|
|
15
|
+
exh = o&.exhibitor(self.class.exhibitor_variant)
|
16
|
+
exh.contextualize(context) if exh.present? && contextualized?
|
17
|
+
|
18
|
+
yield exh
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def to_model
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Exhibitor
|
2
2
|
extend ActiveSupport::Concern
|
3
|
+
attr_accessor :context
|
3
4
|
|
4
5
|
def obj
|
5
6
|
__getobj__
|
@@ -9,7 +10,16 @@ module Exhibitor
|
|
9
10
|
self.class.exhibitor_for(obj)
|
10
11
|
end
|
11
12
|
|
13
|
+
def contextualize(context)
|
14
|
+
self.context = context
|
15
|
+
end
|
16
|
+
|
17
|
+
def contextualized?
|
18
|
+
context.present?
|
19
|
+
end
|
20
|
+
|
12
21
|
module ClassMethods
|
22
|
+
|
13
23
|
def exhibitor_for_super(method, klass = nil)
|
14
24
|
define_method(method) do |*args|
|
15
25
|
klass ||= self.class
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Exposant
|
2
|
-
module
|
2
|
+
module Exposable
|
3
3
|
module Model
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
@@ -9,7 +9,7 @@ module Exposant
|
|
9
9
|
|
10
10
|
module ClassMethods
|
11
11
|
def exhibitor(obj, variant = nil)
|
12
|
-
obj.extend(
|
12
|
+
obj.extend(Exposable::Collection)
|
13
13
|
obj.model_klass = self
|
14
14
|
|
15
15
|
obj.exhibitor(variant)
|
data/lib/exposant/version.rb
CHANGED
data/lib/exposant.rb
CHANGED
@@ -4,8 +4,8 @@ require 'delegate'
|
|
4
4
|
require 'active_support'
|
5
5
|
require 'active_model'
|
6
6
|
|
7
|
-
require_relative 'exposant/concerns/presentable'
|
8
7
|
require_relative 'exposant/concerns/exhibitor'
|
8
|
+
require_relative 'exposant/concerns/exposable'
|
9
9
|
require_relative 'exposant/collection_exhibitor'
|
10
10
|
require_relative 'exposant/model_exhibitor'
|
11
11
|
require_relative 'exposant/version'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exposant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Kienlen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -56,7 +56,7 @@ files:
|
|
56
56
|
- lib/exposant.rb
|
57
57
|
- lib/exposant/collection_exhibitor.rb
|
58
58
|
- lib/exposant/concerns/exhibitor.rb
|
59
|
-
- lib/exposant/concerns/
|
59
|
+
- lib/exposant/concerns/exposable.rb
|
60
60
|
- lib/exposant/model_exhibitor.rb
|
61
61
|
- lib/exposant/version.rb
|
62
62
|
homepage: http://127.0.0.1:3000
|