symbol_decoration 1.0.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +50 -0
  3. data/lib/symbol_decoration.rb +13 -0
  4. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50f521f730b37b3aa512481b9a3cd4ac0df32bdd
4
+ data.tar.gz: ace420edc4102c58d385212e33a83ce639aca91b
5
+ SHA512:
6
+ metadata.gz: 447af63c714e8d6d572a9ae75575c1a5d2009515911b4e32bb5fdff36627961c1b62396f72cf8eaf380785712fe27e142ad68bf7fcc9a196409c1329ddee4358
7
+ data.tar.gz: f03dd020f3df2dc87547ff4e3aa4ba4df29a75ec8c513bdaf814456e3a03bef3c9bfb92950af387ee3fad166db88cf94febd88037a9e2ec448bf71a4701f47c3
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ Symbol Decoration
2
+ =================
3
+
4
+ The Symbol Decoration gem provides symbol method extensions to implement
5
+ DSL such as like `where(:field.in => [1,2,3])`.
6
+
7
+ The goal is to allow different ORMs such as Mongoid and NoBrainer to co-exist as
8
+ both ORMs need such functionality.
9
+
10
+ Usage
11
+ =====
12
+
13
+ In the following example: `where(:field.in => [1,2,3])`, the `in` keyword is a *decorator*, and *decorates* the `:field` symbol.
14
+
15
+ To register decorators, you may call `Symbol::Decoration.register(decorator, ...)`. For example:
16
+
17
+ ```ruby
18
+ Symbol::Decoration.register(:in)
19
+ Symbol::Decoration.register(*%w(in nin eq ne not gt ge gte lt le lte))
20
+ ```
21
+
22
+ Once registered, a decorator can be used with `symbol.decorator`, which returns
23
+ a `Symbol::Decoration` instance.
24
+
25
+ To support the lowest common denominator, decorators may accept arguments and
26
+ blocks. For example, `:field.gt(5)` is valid.
27
+
28
+ You may retrieve the decoration properties with:
29
+
30
+ * `decorated_symbol.symbol` to get the symbol which is being decorated.
31
+ * `decorated_symbol.decorator` to get the decoration (for example `:gt`).
32
+ * `decorated_symbol.args` to get the decoration arguments.
33
+ * `decorated_symbol.blocks` to get the decoration block.
34
+
35
+ Full example:
36
+
37
+ ```ruby
38
+ Symbol::Decoration.register(:gt)
39
+
40
+ :field.gt.class == Symbol::Decoration
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
+ License
48
+ =======
49
+
50
+ Symbol Decoration is MIT Licensed.
@@ -0,0 +1,13 @@
1
+ class Symbol
2
+ Decoration = Struct.new(:symbol, :decorator, :args, :block) do
3
+ def self.register(*decorators)
4
+ Symbol.class_eval do
5
+ decorators.map(&:to_sym).each do |decorator|
6
+ define_method(decorator) do |*args, &block|
7
+ Decoration.new(self, decorator, args, block)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: symbol_decoration
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Viennot
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Support for symbol decorations such as where(:field.in => [1,2,3])
14
+ email:
15
+ - nicolas@viennot.biz
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - lib/symbol_decoration.rb
22
+ homepage: http://github.com/nviennot/symbol_decoration
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.2.2
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Symbol Decoration
46
+ test_files: []
47
+ has_rdoc: false