mystique 0.5.6 → 0.6.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 +5 -5
- data/lib/mystique.rb +15 -13
- data/lib/mystique/presenter.rb +4 -12
- data/lib/mystique/presenters/hash_presenter.rb +2 -2
- data/lib/mystique/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d9603014937dc82f4e81b4e1fce4997aeae3b57c7eb332a00ee6461bf79ecc32
|
4
|
+
data.tar.gz: 34ec93591341d4df02f820fe634f7fcdbc415a762fdcaf5c97f8ad90798bf049
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3588e13a44caf7e17ae68d6c433b1e18d1e4300b167c050b88b0b1ad5aa195ce34115e57f06454e5a546949b76c02d1e2c4acc528d5ce7269518b75011741019
|
7
|
+
data.tar.gz: ed0709c2b2991110952fca79a892fba077f5acc3c14b2a3ea758902de45e48ea58dddb7a3ba31b50d6ea2ef470d3c5767087cd851f97851b477c6ed7fbdb7e8d
|
data/lib/mystique.rb
CHANGED
@@ -10,19 +10,12 @@ module Mystique
|
|
10
10
|
module_function
|
11
11
|
|
12
12
|
def present(object, with: nil, context: nil, &block)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
when Symbol, String
|
21
|
-
StringPlus.constantize("#{with}Presenter")
|
22
|
-
else
|
23
|
-
with
|
24
|
-
end
|
25
|
-
presenter_class.present(object, context, &block)
|
13
|
+
begin
|
14
|
+
presenter_class = presenter_class_for(object, with)
|
15
|
+
presenter_class.present(object, context, &block)
|
16
|
+
rescue NameError
|
17
|
+
return object
|
18
|
+
end
|
26
19
|
end
|
27
20
|
|
28
21
|
def present_collection(collection, context: nil, &block)
|
@@ -32,4 +25,13 @@ module Mystique
|
|
32
25
|
block.call present(element, context: context)
|
33
26
|
end
|
34
27
|
end
|
28
|
+
|
29
|
+
def presenter_class_for(object, with)
|
30
|
+
if with.respond_to?(:present)
|
31
|
+
with
|
32
|
+
else
|
33
|
+
StringPlus.constantize("#{with || object.class}Presenter")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
private :presenter_class_for
|
35
37
|
end
|
data/lib/mystique/presenter.rb
CHANGED
@@ -2,14 +2,8 @@ require "mystique/null_context"
|
|
2
2
|
|
3
3
|
module Mystique
|
4
4
|
class Presenter
|
5
|
-
self.methods.select {|m| m.to_s.start_with?("to_") }.each do |m|
|
6
|
-
define_method(m) do |*args, &block|
|
7
|
-
target.send(m, *args, &block)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
5
|
def initialize(object, context)
|
12
|
-
@__object__
|
6
|
+
@__object__ = object
|
13
7
|
@__context__ = context || self.class.context || NullContext
|
14
8
|
end
|
15
9
|
|
@@ -73,9 +67,7 @@ module Mystique
|
|
73
67
|
end
|
74
68
|
|
75
69
|
def self.__formats__
|
76
|
-
@__formats__ ||= {
|
77
|
-
nil => "-----",
|
78
|
-
}
|
70
|
+
@__formats__ ||= { nil => "-----" }
|
79
71
|
end
|
80
72
|
|
81
73
|
def __regex_formats__
|
@@ -83,7 +75,7 @@ module Mystique
|
|
83
75
|
end
|
84
76
|
|
85
77
|
def self.__regex_formats__
|
86
|
-
@__regex_formats__ ||= __formats__.select {|
|
78
|
+
@__regex_formats__ ||= __formats__.select {|key, _| key.is_a?(Regexp)}
|
87
79
|
end
|
88
80
|
|
89
81
|
def __class_formats__
|
@@ -91,7 +83,7 @@ module Mystique
|
|
91
83
|
end
|
92
84
|
|
93
85
|
def self.__class_formats__
|
94
|
-
@__class_formats__ ||= __formats__.select {|
|
86
|
+
@__class_formats__ ||= __formats__.select {|key, _| key.is_a?(Class)}
|
95
87
|
end
|
96
88
|
end
|
97
89
|
end
|
data/lib/mystique/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mystique
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.7.7
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Ruby presenter gem.
|