symbol_decoration 1.0.0 → 1.1.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 +16 -5
- data/lib/symbol_decoration.rb +26 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4eccd878da79afc079e852f01a7af59a52dcb71
|
4
|
+
data.tar.gz: 9c18b97ad316f76374d79981c1b95b4e8bbc1a02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eab8bb0207b68c606ad5594b5df2c31d53ddd418d453579ac3edf834a873eb398dfb0c06a46d37b4960ae87470ea9667a168e4dc84721afb8da28dd4e395ce37
|
7
|
+
data.tar.gz: f31c9d730c6f8ce22f1bd26b71f8a51069a8472330f266bac410a6bc2dcfacfc19598457a35feaa68b1f7f1f09cd0fbfcd6bc887536e34ddafe01f37958ebb26
|
data/README.md
CHANGED
@@ -37,11 +37,22 @@ Full example:
|
|
37
37
|
```ruby
|
38
38
|
Symbol::Decoration.register(:gt)
|
39
39
|
|
40
|
-
:field.gt.
|
41
|
-
:field.gt.symbol
|
42
|
-
:field.gt.decorator
|
43
|
-
:field.gt(5).args
|
44
|
-
:field.gt { 5 }.block.call
|
40
|
+
:field.gt.is_a?(Symbol::Decoration) == true
|
41
|
+
:field.gt.symbol == :field
|
42
|
+
:field.gt.decorator == :gt
|
43
|
+
:field.gt(5).args == [5]
|
44
|
+
:field.gt { 5 }.block.call == 5
|
45
|
+
```
|
46
|
+
|
47
|
+
To allow certain decorators to be chainable, you must use the `:chainable =>
|
48
|
+
true` option when registering the decorator. Example:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
Symbol::Decoration.register(:any, chainable => true)
|
52
|
+
Symbol::Decoration.register(:in)
|
53
|
+
|
54
|
+
:field.any.in # valid
|
55
|
+
:field.in.any # invalid
|
45
56
|
```
|
46
57
|
|
47
58
|
License
|
data/lib/symbol_decoration.rb
CHANGED
@@ -1,13 +1,35 @@
|
|
1
1
|
class Symbol
|
2
|
-
Decoration
|
2
|
+
class Decoration < Struct.new(:symbol, :decorator, :args, :block)
|
3
|
+
module Extensions; end
|
4
|
+
|
5
|
+
class << self; attr_accessor :decorator_options; end
|
6
|
+
self.decorator_options = {}
|
7
|
+
|
3
8
|
def self.register(*decorators)
|
4
|
-
|
5
|
-
|
9
|
+
options = decorators.last.is_a?(Hash) ? decorators.pop : {}
|
10
|
+
decorators.map(&:to_sym).each do |decorator|
|
11
|
+
self.decorator_options[decorator] = (self.decorator_options[decorator] || {}).merge(options)
|
12
|
+
klass = self.decorator_options[decorator][:chainable] ? ChainableDecoration : Decoration
|
13
|
+
Extensions.module_eval do
|
6
14
|
define_method(decorator) do |*args, &block|
|
7
|
-
|
15
|
+
klass.new(self, decorator, args, block)
|
8
16
|
end
|
9
17
|
end
|
10
18
|
end
|
11
19
|
end
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
s = "#{symbol.inspect}.#{decorator}"
|
23
|
+
_args = block ? args + [block] : args
|
24
|
+
s += "(#{_args.map(&:inspect).join(", ")})" unless _args.empty?
|
25
|
+
s
|
26
|
+
end
|
27
|
+
alias_method :to_s, :inspect
|
28
|
+
end
|
29
|
+
|
30
|
+
class ChainableDecoration < Decoration
|
31
|
+
include Decoration::Extensions
|
12
32
|
end
|
33
|
+
|
34
|
+
include Decoration::Extensions
|
13
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: symbol_decoration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Viennot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Support for symbol decorations such as where(:field.in => [1,2,3])
|
14
14
|
email:
|
@@ -39,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
41
|
rubyforge_project:
|
42
|
-
rubygems_version: 2.
|
42
|
+
rubygems_version: 2.4.2
|
43
43
|
signing_key:
|
44
44
|
specification_version: 4
|
45
45
|
summary: Symbol Decoration
|