mystique 0.1.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/lib/mystique.rb +22 -13
- data/lib/mystique/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73d0338f218a8478a975c8efc740cd95a4b44e10
|
4
|
+
data.tar.gz: 3fa3343e877ef60871799cd936a088dd319dc1ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82f86b6790a48e65cf8a86d16c3700a69741fb087465e3e9ccbaf73bef817ac90aa3af35ab5366e586e8758f235db213693e92aadd3dcb5584b8003dbf55593c
|
7
|
+
data.tar.gz: 7903d2a4720b5d04e5dd3df49e1c60cbfbbb64660e292aa4979a9711275c532f85d73ff85da399c0af7c3cfd7ca97ecce71be39f059988c110b36be25e278fe2
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Mystique
|
2
2
|
|
3
|
-
|
3
|
+
Mystique is a gem that implements the presenter pattern. It allows you to augment an object, by wrapping it and giving it access to the context in which you need to render it.
|
4
4
|
|
5
|
-
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
TODO: Write usage instructions here
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -20,9 +22,6 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
$ gem install mystique
|
22
24
|
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
25
|
|
27
26
|
## Development
|
28
27
|
|
data/lib/mystique.rb
CHANGED
@@ -6,16 +6,20 @@ module Mystique
|
|
6
6
|
class Presenter
|
7
7
|
def initialize(object, context)
|
8
8
|
@__object__ = object
|
9
|
-
@__context__ = context
|
9
|
+
@__context__ = context || self.class.context
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.present(object)
|
13
|
-
new(object, context)
|
12
|
+
def self.present(object, context=nil)
|
13
|
+
self.new(object, context).tap do |presenter|
|
14
|
+
yield presenter if block_given?
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
|
-
def
|
17
|
-
@__context__
|
18
|
+
def context
|
19
|
+
@__context__
|
18
20
|
end
|
21
|
+
alias :ctx :context
|
22
|
+
alias :h :context
|
19
23
|
|
20
24
|
def target
|
21
25
|
@__object__
|
@@ -34,7 +38,7 @@ module Mystique
|
|
34
38
|
else
|
35
39
|
value
|
36
40
|
end
|
37
|
-
Callable(result).call(value)
|
41
|
+
Callable(result).call(value, context)
|
38
42
|
end
|
39
43
|
|
40
44
|
def self.context(ctx=Undefined)
|
@@ -42,10 +46,16 @@ module Mystique
|
|
42
46
|
@__context__
|
43
47
|
end
|
44
48
|
|
45
|
-
def self.format(
|
46
|
-
__formats__[
|
49
|
+
def self.format(matcher, value=nil, &block)
|
50
|
+
__formats__[matcher] = block_given? ? block : value
|
47
51
|
end
|
48
52
|
|
53
|
+
def self.format_multiple(*matchers, &block)
|
54
|
+
matchers.each do |matcher|
|
55
|
+
format(matcher, &block)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
49
59
|
def __formats__
|
50
60
|
self.class.__formats__
|
51
61
|
end
|
@@ -77,16 +87,15 @@ module Mystique
|
|
77
87
|
|
78
88
|
module_function
|
79
89
|
|
80
|
-
def present(object, with: nil)
|
81
|
-
from_module &&= "#{from_module.to_s.camelcase}::"
|
90
|
+
def present(object, with: nil, context: nil, &block)
|
82
91
|
presenter_class = case with
|
83
92
|
when nil
|
84
93
|
"#{object.class}Presenter".constantize
|
85
94
|
when Symbol, String
|
86
|
-
"#{
|
95
|
+
"#{with}Presenter".constantize
|
87
96
|
else
|
88
|
-
|
97
|
+
with
|
89
98
|
end
|
90
|
-
presenter_class.present(object)
|
99
|
+
presenter_class.present(object, context, &block)
|
91
100
|
end
|
92
101
|
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.3.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: 2015-03-
|
11
|
+
date: 2015-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|