arel_extension 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 927f3ddcd3bff3bee5fe3c5d0bf67dfdfebd827e
4
+ data.tar.gz: a2970aa831a46310eb84800c03cdbffd9e9c3402
5
+ SHA512:
6
+ metadata.gz: 8cf69b2edb3faba56b520875ef3f1f5a5e364000f0b8945975a3132a8cf387a4655803018de47446ba43c39e16415ed73a002e7967ae93d82854f9e3bc1d904e
7
+ data.tar.gz: a36b1128a5e5e5059369811802f6f808c15b3ca2607707c390c521cb0e530a81cbc8e3b50378d6e09f111d8e4dc20dd3ea6e0554243efa39486300dba2b9421f
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ todo.txt
11
+ .rspec
12
+ *.gem
13
+ *.rbc
14
+ .bundle
15
+ .config
16
+ InstalledFiles
17
+ lib/bundler/man
18
+ rdoc
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in arel_extension.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Kuldeep Aggarwal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # ArelExtension
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/arel_extension`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'arel_extension'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install arel_extension
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/arel_extension/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'arel_extension/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "arel_extension"
8
+ spec.version = ArelExtension::VERSION
9
+ spec.authors = ["Kuldeep Aggarwal"]
10
+ spec.email = ["kd.engineer@yahoo.co.in"]
11
+
12
+ spec.summary = %q{Extension of Arel Gem}
13
+ spec.description = %q{Extension of Arel Gem.}
14
+ spec.homepage = "https://github.com/kuldeepaggarwal/arel_extension"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'arel', '>= 4', '< 5'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.9"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "arel_extension"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require 'arel_extension/version'
2
+ require 'arel_extension/attributes/attribute_extension'
3
+ require 'arel_extension/nodes/case'
4
+ require 'arel_extension/nodes/coalesce'
5
+ require 'arel_extension/expressions'
6
+ require 'arel_extension/predications'
7
+ require 'arel_extension/factory_methods'
8
+
9
+ module ArelExtension
10
+ end
@@ -0,0 +1,11 @@
1
+ module Arel
2
+ module Attributes
3
+ module AttributeExtension
4
+ def date
5
+ Arel::Nodes::NamedFunction.new('DATE', [self])
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ Arel::Attributes::Attribute.send :include, Arel::Attributes::AttributeExtension
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Expressions
3
+ def sum_without_alias
4
+ Nodes::Sum.new([self])
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module Arel
2
+ module FactoryMethods
3
+ module_function
4
+ def switch
5
+ Arel::Nodes::Case.new
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,118 @@
1
+ # CASE implementation for Arel
2
+ # Based on: https://github.com/take-five/acts_as_ordered_tree/blob/master/lib/acts_as_ordered_tree/transaction/dsl.rb
3
+ # Extended with support for CASE expr WHEN expr[, expr, ...] by Felix Buenemann
4
+ # https://gist.github.com/felixbuenemann/eb2e0f6c66469a98f748
5
+
6
+ module Arel
7
+ module Nodes
8
+ # Case node
9
+ #
10
+ # @example
11
+ # switch.when(table[:x].gt(1), table[:y]).else(table[:z])
12
+ # # CASE WHEN "table"."x" > 1 THEN "table"."y" ELSE "table"."z" END
13
+ # switch.when(table[:x].gt(1)).then(table[:y]).else(table[:z])
14
+ class Case < ::Arel::Nodes::Node
15
+ include Arel::Expression
16
+ include Arel::Expressions
17
+ include Arel::Predications
18
+ include Arel::AliasPredication
19
+
20
+ attr_reader :conditions, :default
21
+
22
+ def initialize
23
+ @conditions = []
24
+ @default = nil
25
+ end
26
+
27
+ def when(condition, expression = nil)
28
+ @conditions << When.new(condition, expression)
29
+ self
30
+ end
31
+
32
+ def then(expression)
33
+ @conditions.last.right = expression
34
+ self
35
+ end
36
+
37
+ def else(expression)
38
+ @default = Else.new(expression)
39
+ self
40
+ end
41
+ end
42
+
43
+ class When < Arel::Nodes::Binary
44
+ end
45
+
46
+ class Else < Arel::Nodes::Unary
47
+ end
48
+ end
49
+
50
+ module Visitors
51
+ class ToSql < ::Arel::Visitors::ToSql.superclass
52
+ private
53
+ def visit_Arel_Nodes_Case o, *a
54
+ conditions = o.conditions.map { |x| visit x, *a }.join(' ')
55
+ default = o.default && visit(o.default, *a)
56
+
57
+ "CASE #{[conditions, default].compact.join(' ')} END"
58
+ end
59
+
60
+ def visit_Arel_Nodes_When o, *a
61
+ "WHEN #{visit o.left, *a} THEN #{visit o.right, *a}"
62
+ end
63
+
64
+ def visit_Arel_Nodes_Else o, *a
65
+ "ELSE #{visit o.expr, *a}"
66
+ end
67
+
68
+ def visit_Arel_Nodes_Coalesce(o, *a)
69
+ "COALESCE(#{visit o.left}, #{visit o.right, *a})#{o.aliaz ? " AS #{visit o.aliaz, *a}" : ''}"
70
+ end
71
+
72
+ if Arel::VERSION >= '6.0.0'
73
+ def visit_Arel_Nodes_Case o, collector
74
+ collector << 'CASE '
75
+ o.conditions.each do |x|
76
+ visit x, collector
77
+ collector << ' '
78
+ end
79
+ if o.default
80
+ visit o.default, collector
81
+ collector << ' '
82
+ end
83
+ collector << 'END'
84
+ end
85
+
86
+ def visit_Arel_Nodes_When o, collector
87
+ collector << 'WHEN '
88
+ visit o.left, collector
89
+ collector << ' THEN '
90
+ visit o.right, collector
91
+ end
92
+
93
+ def visit_Arel_Nodes_Else o, collector
94
+ collector << 'ELSE'
95
+ visit o.expr, collector
96
+ end
97
+
98
+ def visit_NilClass o, collector
99
+ collector << 'NULL'
100
+ end
101
+ end
102
+ end
103
+
104
+ class DepthFirst < ::Arel::Visitors::DepthFirst.superclass
105
+ def visit_Arel_Nodes_Case o, *a
106
+ visit o.conditions, *a
107
+ visit o.default, *a
108
+ end
109
+
110
+ def method_name
111
+ visit o.alias, a
112
+ end
113
+ alias :visit_Arel_Nodes_When :binary
114
+ alias :visit_Arel_Nodes_Else :unary
115
+ alias :visit_Arel_Nodes_Coalesce :binary
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,37 @@
1
+ module Arel
2
+ module Nodes
3
+ class Coalesce < Arel::Nodes::Binary
4
+ attr_reader :aliaz
5
+ def initialize(left, right, aliaz = nil)
6
+ super(left, right)
7
+ as(aliaz)
8
+ end
9
+
10
+ def as(aliaz)
11
+ @aliaz = aliaz && SqlLiteral.new(aliaz)
12
+ self
13
+ end
14
+
15
+ def hash
16
+ super ^ @aliaz.hash
17
+ end
18
+
19
+ def eql? other
20
+ super && @aliaz == other.aliaz
21
+ end
22
+ end
23
+ end
24
+
25
+ module Visitors
26
+ class ToSql < ::Arel::Visitors::ToSql.superclass
27
+ private
28
+ def visit_Arel_Nodes_Coalesce(o, *a)
29
+ "COALESCE(#{visit o.left}, #{visit o.right, *a})#{o.aliaz ? " AS #{visit o.aliaz, *a}" : ''}"
30
+ end
31
+ end
32
+
33
+ class DepthFirst < ::Arel::Visitors::DepthFirst.superclass
34
+ alias :visit_Arel_Nodes_Coalesce :binary
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ module Predications
3
+ def coalesce(value)
4
+ Arel::Nodes::Coalesce.new([self], value, Nodes::SqlLiteral.new('coalesce_id'))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module ArelExtension
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arel_extension
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kuldeep Aggarwal
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: arel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.9'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.9'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ description: Extension of Arel Gem.
62
+ email:
63
+ - kd.engineer@yahoo.co.in
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".travis.yml"
70
+ - CODE_OF_CONDUCT.md
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - arel_extension.gemspec
76
+ - bin/console
77
+ - bin/setup
78
+ - lib/arel_extension.rb
79
+ - lib/arel_extension/attributes/attribute_extension.rb
80
+ - lib/arel_extension/expressions.rb
81
+ - lib/arel_extension/factory_methods.rb
82
+ - lib/arel_extension/nodes/case.rb
83
+ - lib/arel_extension/nodes/coalesce.rb
84
+ - lib/arel_extension/predications.rb
85
+ - lib/arel_extension/version.rb
86
+ homepage: https://github.com/kuldeepaggarwal/arel_extension
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.6
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Extension of Arel Gem
110
+ test_files: []