rails_compatable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +19 -0
- data/.travis.yml +2 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +9 -0
- data/Rakefile +3 -0
- data/lib/rails_compatable/active_record/base.rb +54 -0
- data/lib/rails_compatable/active_record/relation.rb +54 -0
- data/lib/rails_compatable/version.rb +3 -0
- data/lib/rails_compatable.rb +2 -0
- data/rails_compatable.gemspec +23 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c13d478627bc8cdc6e0d2d3eb416470bd1c19cd
|
4
|
+
data.tar.gz: 2111b688332f326f27a9574e5c4b12422d4ddd4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7a9695f585fe55b8f96925faa51eb4800aab5a4259b1b37ac03213ceeb70e23a839cba97c92896b6c7cfe2fe1fbf1c38b6cdfe0577253ba8e6086e93f069b72
|
7
|
+
data.tar.gz: 022240331149b39c5ab69471746aa05a2e801125e4f2a47fe42021897edba37b7ddbeec5ab643b48d6f447a13c74827d8ccd5c6d1a9a7586e6c639fef560f0a3
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Jianqiu Xiao <swordray@gmail.com>
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# rails-compatable
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rails_compatable.png)](http://badge.fury.io/rb/rails_compatable) [![Build Status](https://secure.travis-ci.org/swordray/rails_compatable.png?branch=master)](http://travis-ci.org/swordray/rails_compatable) [![Dependency Status](https://gemnasium.com/swordray/rails_compatable.png?travis)](https://gemnasium.com/swordray/rails_compatable) [![Code Climate](https://codeclimate.com/github/swordray/rails_compatable.png)](https://codeclimate.com/github/swordray/rails_compatable)
|
4
|
+
|
5
|
+
Make Rails 2 / 3 / 4 application code compatable
|
6
|
+
|
7
|
+
## TODO
|
8
|
+
|
9
|
+
TODO
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Base
|
3
|
+
class << self
|
4
|
+
def find_by(*args)
|
5
|
+
where(*args).take
|
6
|
+
end unless method_defined?(:find_by)
|
7
|
+
|
8
|
+
def take(limit = nil)
|
9
|
+
limit ? limit(limit).to_a : find_take
|
10
|
+
end unless method_defined?(:take)
|
11
|
+
|
12
|
+
def find_take
|
13
|
+
if loaded?
|
14
|
+
@records.first
|
15
|
+
else
|
16
|
+
@take ||= limit(1).to_a.first
|
17
|
+
end
|
18
|
+
end unless method_defined?(:find_take)
|
19
|
+
|
20
|
+
def find_or_initialize_by(attributes, &block)
|
21
|
+
find_by(attributes) || new(attributes, &block)
|
22
|
+
end unless method_defined?(:find_or_initialize_by)
|
23
|
+
|
24
|
+
def set_table_name(name)
|
25
|
+
table_name = name
|
26
|
+
end unless method_defined?(:set_table_name)
|
27
|
+
|
28
|
+
def scoped(options = {})
|
29
|
+
records = self.where(true)
|
30
|
+
scoped_methods = %w[conditions from group having includes joins limit lock offset order readonly select]
|
31
|
+
options.with_indifferent_access.slice(*scoped_methods).each do |method, params|
|
32
|
+
records = records.send(method, params)
|
33
|
+
end
|
34
|
+
records
|
35
|
+
end unless method_defined?(:scoped)
|
36
|
+
|
37
|
+
def conditions(*args)
|
38
|
+
where(*args)
|
39
|
+
end unless method_defined?(:conditions)
|
40
|
+
|
41
|
+
def method_missing(*args)
|
42
|
+
matched, new_method, fields_joined_by_end = args.first.to_s.match(/(find_by|find_or_initialize_by)_(\w+)/).to_a
|
43
|
+
return send(new_method, [fields_joined_by_end.split('_and_'), args[1..-1]].transpose.to_h) if matched
|
44
|
+
raise NoMethodError, "undefined method '#{args.first}'"
|
45
|
+
end
|
46
|
+
|
47
|
+
def all_with_args(*args)
|
48
|
+
return all_without_args if args.blank?
|
49
|
+
scoped(*args)
|
50
|
+
end
|
51
|
+
alias_method_chain :all, :args if method_defined?(:all)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Relation
|
3
|
+
class << self
|
4
|
+
def find_by(*args)
|
5
|
+
where(*args).take
|
6
|
+
end unless method_defined?(:find_by)
|
7
|
+
|
8
|
+
def take(limit = nil)
|
9
|
+
limit ? limit(limit).to_a : find_take
|
10
|
+
end unless method_defined?(:take)
|
11
|
+
|
12
|
+
def find_take
|
13
|
+
if loaded?
|
14
|
+
@records.first
|
15
|
+
else
|
16
|
+
@take ||= limit(1).to_a.first
|
17
|
+
end
|
18
|
+
end unless method_defined?(:find_take)
|
19
|
+
|
20
|
+
def find_or_initialize_by(attributes, &block)
|
21
|
+
find_by(attributes) || new(attributes, &block)
|
22
|
+
end unless method_defined?(:find_or_initialize_by)
|
23
|
+
|
24
|
+
def set_table_name(name)
|
25
|
+
table_name = name
|
26
|
+
end unless method_defined?(:set_table_name)
|
27
|
+
|
28
|
+
def scoped(options = {})
|
29
|
+
records = self.where(true)
|
30
|
+
scoped_methods = %w[conditions from group having includes joins limit lock offset order readonly select]
|
31
|
+
options.with_indifferent_access.slice(*scoped_methods).each do |method, params|
|
32
|
+
records = records.send(method, params)
|
33
|
+
end
|
34
|
+
records
|
35
|
+
end unless method_defined?(:scoped)
|
36
|
+
|
37
|
+
def conditions(*args)
|
38
|
+
where(*args)
|
39
|
+
end unless method_defined?(:conditions)
|
40
|
+
|
41
|
+
def method_missing(*args)
|
42
|
+
matched, new_method, fields_joined_by_end = args.first.to_s.match(/(find_by|find_or_initialize_by)_(\w+)/).to_a
|
43
|
+
return send(new_method, [fields_joined_by_end.split('_and_'), args[1..-1]].transpose.to_h) if matched
|
44
|
+
raise NoMethodError, "undefined method '#{args.first}'"
|
45
|
+
end
|
46
|
+
|
47
|
+
def all_with_args(*args)
|
48
|
+
return all_without_args if args.blank?
|
49
|
+
scoped(*args)
|
50
|
+
end
|
51
|
+
alias_method_chain :all, :args if method_defined?(:all)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
2
|
+
require 'rails_compatable/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "rails_compatable"
|
6
|
+
s.version = RailsCompatable::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.author = ["Jianqiu Xiao"]
|
9
|
+
s.email = ["swordray@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/swordray/rails_compatable"
|
11
|
+
s.summary = "Make Rails 2 / 3 / 4 application code compatable"
|
12
|
+
s.description = "Make Rails 2 / 3 / 4 application code compatable."
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.required_ruby_version = "~> 2.0"
|
21
|
+
|
22
|
+
s.add_dependency 'rails'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_compatable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jianqiu Xiao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Make Rails 2 / 3 / 4 application code compatable.
|
28
|
+
email:
|
29
|
+
- swordray@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".DS_Store"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".travis.yml"
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/rails_compatable.rb
|
42
|
+
- lib/rails_compatable/active_record/base.rb
|
43
|
+
- lib/rails_compatable/active_record/relation.rb
|
44
|
+
- lib/rails_compatable/version.rb
|
45
|
+
- rails_compatable.gemspec
|
46
|
+
homepage: https://github.com/swordray/rails_compatable
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - "~>"
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '2.0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.2.2
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Make Rails 2 / 3 / 4 application code compatable
|
70
|
+
test_files: []
|