ar-column-as 0.0.2

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 (6) hide show
  1. data/Gemfile +16 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +3 -0
  4. data/Rakefile +25 -0
  5. data/lib/ar-column-as.rb +40 -0
  6. metadata +67 -0
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rails", "~> 3.0"
6
+
7
+ gem 'sqlite3'
8
+
9
+ group :test do
10
+ gem 'capybara'
11
+ gem 'mocha', :require => false
12
+ end
13
+
14
+ # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
15
+ # gem 'ruby-debug'
16
+ # gem 'ruby-debug19'
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ Adds a few simple helper methods that can be used with ActiveRecord::select.
2
+
3
+ This project uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'bundler'
10
+
11
+ require 'rake'
12
+ require 'rake/rdoctask'
13
+
14
+ require 'rake/testtask'
15
+
16
+ Bundler::GemHelper.install_tasks
17
+
18
+ Rake::TestTask.new(:test) do |t|
19
+ t.libs << 'lib'
20
+ t.libs << 'test'
21
+ t.pattern = 'test/**/*_test.rb'
22
+ t.verbose = false
23
+ end
24
+
25
+ task :default => :test
@@ -0,0 +1,40 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ class SQLiteAdapter < AbstractAdapter
4
+ def year_calc(column)
5
+ "strftime('%Y', #{column.to_s})"
6
+ end
7
+
8
+ def month_calc(column)
9
+ "strftime('%m', #{column.to_s})"
10
+ end
11
+ end
12
+
13
+ class MysqlAdapter < AbstractAdapter
14
+ def year_calc(column)
15
+ "YEAR(#{column.to_s})"
16
+ end
17
+
18
+ def month_calc(column)
19
+ "MONTH(#{column.to_s})"
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ module Sql
26
+ def Sql.column_as(column, options = {})
27
+ out = [column]
28
+ out << "AS '#{options[:as]}'" if options[:as]
29
+ out.join(' ')
30
+ end
31
+
32
+ def Sql.year(column, options = {})
33
+ column_as(ActiveRecord::Base.connection.year_calc(column), options)
34
+ end
35
+
36
+ def Sql.month(column, options = {})
37
+ column_as(ActiveRecord::Base.connection.month_calc(column), options)
38
+ end
39
+ end
40
+
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ar-column-as
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Hinni
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-20 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Basic column_as support for ActiveRecord
18
+ email:
19
+ - aaron@vedadev.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - lib/ar-column-as.rb
28
+ - MIT-LICENSE
29
+ - Rakefile
30
+ - Gemfile
31
+ - README
32
+ has_rdoc: true
33
+ homepage: http://vedadev.com
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 1609137101423134360
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 1609137101423134360
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.5.2
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Basic column_as support for ActiveRecord
66
+ test_files: []
67
+