webink_r 0.4.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/LICENSE.md +22 -0
  3. data/lib/webink/r.rb +62 -0
  4. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b97368798aaab89b531d4714619e4d19cc0203a8
4
+ data.tar.gz: 844c481cd96401a0e6c377ac50ffcd63c67211e5
5
+ SHA512:
6
+ metadata.gz: 1f71fbd1a23d14fa4a2dfcd7d49415bc10ae17dadbaaa934ce48ed9dbdf22b2336728a3cd3586b4350f47f01f8137f53c9c86720d046777eb71c7947ae20e071
7
+ data.tar.gz: 3d3643bfe19854e484357dc613c6304114813e55f41845e9a8986ae7dbc79b191f829cbb0e0b8ce9a734798a1ef419c3e30977f972a82d2edbd83257aee6097a
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014, Matthias Geier
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ - Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ - Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
17
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/lib/webink/r.rb ADDED
@@ -0,0 +1,62 @@
1
+ module Ink
2
+ def self.R!(*args, &blk)
3
+ return Ink::R::RelationString.new(Ink::R::build("_!", *args, &blk))
4
+ end
5
+
6
+ module R
7
+ class RelationString
8
+ def initialize(str="")
9
+ @sql = [str]
10
+ end
11
+
12
+ def method_missing(prefix, *args, &blk)
13
+ @sql << Ink::R::build(prefix, *args, &blk)
14
+ return self
15
+ end
16
+
17
+ def to_s
18
+ return @sql.flatten.join
19
+ end
20
+ alias_method :to_sql, :to_s
21
+ alias_method :to_str, :to_s
22
+ end
23
+
24
+ def self.method_missing(prefix, *args, &blk)
25
+ return RelationString.new(self.build(prefix, *args, &blk))
26
+ end
27
+
28
+ def self.build(prefix, *args, &blk)
29
+ prefix = prefix.to_s.upcase
30
+ prefix, control_chars = self.split_control_chars(prefix)
31
+
32
+ space_prefix = control_chars.include?('_') ? '' : ' '
33
+ wrap_chars = control_chars.include?('!') ?
34
+ [space_prefix + '(', ')'] :
35
+ [space_prefix, '']
36
+ prefix_prefix = control_chars.include?('_') &&
37
+ control_chars.include?('!') ? '' : ' '
38
+
39
+ str = prefix.empty? ? [] : [prefix_prefix + prefix]
40
+ str << (!args.empty? || blk ? wrap_chars[0] : '')
41
+ unless args.empty?
42
+ str << args.map(&:to_s).join(', ')
43
+ end
44
+ if blk
45
+ str << blk.call(RelationString.new).to_s
46
+ end
47
+ str << (!args.empty? || blk ? wrap_chars[1] : '')
48
+ return str
49
+ end
50
+
51
+ private
52
+ def self.split_control_chars(string)
53
+ control_char_match = string.match(/([_!]+)$/)
54
+ if control_char_match
55
+ m = control_char_match[1]
56
+ return [string[0, string.length - m.length], m.split('')]
57
+ else
58
+ return [string, []]
59
+ end
60
+ end
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webink_r
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthias Geier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE.md
20
+ - lib/webink/r.rb
21
+ homepage: https://github.com/matthias-geier/webink_r
22
+ licenses: []
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.9.3
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.0
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: a minimal chainable sql string builder
44
+ test_files: []