eel 0.0.2 → 1.0.0.pre
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.
- data/lib/eel/active_record/query_extensions.rb +2 -2
- data/lib/eel/core_ext/symbol_extensions.rb +42 -0
- data/lib/eel/version.rb +1 -1
- data/lib/eel.rb +5 -5
- metadata +7 -23
- data/.gitignore +0 -18
- data/.rbenv-version +0 -1
- data/Gemfile +0 -9
- data/LICENSE.txt +0 -22
- data/README.md +0 -3
- data/Rakefile +0 -4
- data/eel.gemspec +0 -21
- data/lib/eel/active_record.rb +0 -1
- data/lib/eel/core_ext/symbol.rb +0 -37
- data/spec/dsl/dsl_spec.rb +0 -44
- data/spec/factories/todo_item.rb +0 -9
- data/spec/spec_helper.rb +0 -26
- data/spec/support/active_record.rb +0 -17
@@ -4,12 +4,12 @@ module Eel
|
|
4
4
|
|
5
5
|
def order *args
|
6
6
|
return self if args.blank?
|
7
|
-
super *args.flatten.map { |a| a.
|
7
|
+
super *args.flatten.map { |a| assign_context(a.expr) if a.respond_to?(:expr); a }
|
8
8
|
end
|
9
9
|
|
10
10
|
def reorder *args
|
11
11
|
return self if args.blank?
|
12
|
-
super *args.flatten.map { |a| a.
|
12
|
+
super *args.flatten.map { |a| assign_context(a.expr) if a.respond_to?(:expr); a }
|
13
13
|
end
|
14
14
|
|
15
15
|
def build_where(opts, other = [])
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Eel
|
2
|
+
module CoreExt
|
3
|
+
module SymbolExtensions
|
4
|
+
|
5
|
+
def attr
|
6
|
+
Arel::Attributes::Attribute.new(nil, self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def of val
|
10
|
+
relation = case val
|
11
|
+
when Class
|
12
|
+
val.arel_table
|
13
|
+
when Symbol
|
14
|
+
val
|
15
|
+
when String
|
16
|
+
Arel::Table.new(val)
|
17
|
+
else
|
18
|
+
raise "Can't use #{val.class} as a relation"
|
19
|
+
end
|
20
|
+
|
21
|
+
Arel::Attributes::Attribute.new(relation, self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def respond_to_missing? method_name, private = false
|
25
|
+
Arel::Attributes::Attribute.new.respond_to?(method_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing method_name, *args, &block
|
29
|
+
if (attr = Arel::Attributes::Attribute.new(nil, self)).respond_to?(method_name)
|
30
|
+
if args.present?
|
31
|
+
attr.send(method_name, *args) # binary nodes
|
32
|
+
else
|
33
|
+
attr.send(method_name) # unary nodes
|
34
|
+
end
|
35
|
+
else
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/eel/version.rb
CHANGED
data/lib/eel.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'eel/version'
|
2
2
|
|
3
|
-
|
3
|
+
require 'eel/active_record/query_extensions'
|
4
|
+
require 'eel/core_ext/symbol_extensions'
|
5
|
+
|
6
|
+
ActiveRecord::Relation.send :include, Eel::ActiveRecord::QueryExtensions
|
7
|
+
Symbol.send :include, Eel::CoreExt::SymbolExtensions
|
4
8
|
|
5
|
-
end
|
6
9
|
|
7
|
-
require 'eel/active_record/query_extensions'
|
8
|
-
require 'eel/active_record'
|
9
|
-
require 'eel/core_ext/symbol'
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0.pre
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ivan Efremov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -52,22 +52,10 @@ executables: []
|
|
52
52
|
extensions: []
|
53
53
|
extra_rdoc_files: []
|
54
54
|
files:
|
55
|
-
- .gitignore
|
56
|
-
- .rbenv-version
|
57
|
-
- Gemfile
|
58
|
-
- LICENSE.txt
|
59
|
-
- README.md
|
60
|
-
- Rakefile
|
61
|
-
- eel.gemspec
|
62
55
|
- lib/eel.rb
|
63
|
-
- lib/eel/active_record.rb
|
64
56
|
- lib/eel/active_record/query_extensions.rb
|
65
|
-
- lib/eel/core_ext/
|
57
|
+
- lib/eel/core_ext/symbol_extensions.rb
|
66
58
|
- lib/eel/version.rb
|
67
|
-
- spec/dsl/dsl_spec.rb
|
68
|
-
- spec/factories/todo_item.rb
|
69
|
-
- spec/spec_helper.rb
|
70
|
-
- spec/support/active_record.rb
|
71
59
|
homepage: https://github.com/StrangeMood/eel
|
72
60
|
licenses: []
|
73
61
|
post_install_message:
|
@@ -83,17 +71,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
72
|
none: false
|
85
73
|
requirements:
|
86
|
-
- - ! '
|
74
|
+
- - ! '>'
|
87
75
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
76
|
+
version: 1.3.1
|
89
77
|
requirements: []
|
90
78
|
rubyforge_project:
|
91
79
|
rubygems_version: 1.8.23
|
92
80
|
signing_key:
|
93
81
|
specification_version: 3
|
94
82
|
summary: It is more like Squeel but without Squ
|
95
|
-
test_files:
|
96
|
-
- spec/dsl/dsl_spec.rb
|
97
|
-
- spec/factories/todo_item.rb
|
98
|
-
- spec/spec_helper.rb
|
99
|
-
- spec/support/active_record.rb
|
83
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rbenv-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.9.3-p327
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Ivan Efremov
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
data/Rakefile
DELETED
data/eel.gemspec
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'eel/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |gem|
|
7
|
-
gem.name = 'eel'
|
8
|
-
gem.version = Eel::VERSION
|
9
|
-
gem.authors = ['Ivan Efremov', 'Anatoly Lapshin']
|
10
|
-
gem.email = ['st8998@gmail.com', 'holywarez@gmail.com']
|
11
|
-
gem.description = %q{It is more like Squeel but without Squ}
|
12
|
-
gem.summary = %q{It is more like Squeel but without Squ}
|
13
|
-
gem.homepage = 'https://github.com/StrangeMood/eel'
|
14
|
-
|
15
|
-
gem.add_dependency 'activerecord', '~> 3.2'
|
16
|
-
gem.add_dependency 'activesupport', '~> 3.2'
|
17
|
-
|
18
|
-
gem.files = `git ls-files`.split($/)
|
19
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
-
gem.require_paths = ['lib']
|
21
|
-
end
|
data/lib/eel/active_record.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ActiveRecord::Relation.send :include, Eel::ActiveRecord::QueryExtensions
|
data/lib/eel/core_ext/symbol.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
class Symbol
|
2
|
-
|
3
|
-
delegate :gt, :gteq, :lt, :lteq,
|
4
|
-
:eq, :not_eq, :in, :not_in,
|
5
|
-
:desc, :asc,
|
6
|
-
to: :attr
|
7
|
-
|
8
|
-
def between *other
|
9
|
-
other = other.flatten
|
10
|
-
Arel::Nodes::Between.new(attr, Arel::Nodes::And.new(other))
|
11
|
-
end
|
12
|
-
|
13
|
-
def attr
|
14
|
-
attr = Arel::Attributes::Attribute.new
|
15
|
-
attr.name = self
|
16
|
-
attr
|
17
|
-
end
|
18
|
-
|
19
|
-
def of val
|
20
|
-
relation = case val
|
21
|
-
when Class
|
22
|
-
val.arel_table
|
23
|
-
when Symbol
|
24
|
-
val
|
25
|
-
when String
|
26
|
-
val.classify.constantize
|
27
|
-
else
|
28
|
-
raise "Can't use #{val.class} as a relation"
|
29
|
-
end
|
30
|
-
|
31
|
-
attr = Arel::Attributes::Attribute.new
|
32
|
-
attr.name = self
|
33
|
-
attr.relation = relation
|
34
|
-
attr
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
data/spec/dsl/dsl_spec.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Eel query dsl' do
|
4
|
-
context 'Simple filtering' do
|
5
|
-
before do
|
6
|
-
3.times do |index|
|
7
|
-
create(:todo_item, score_points: index + 1, due_date: Date.current + index.days)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'greater than' do
|
12
|
-
subject { TodoItem.where(:score_points.gt 2) }
|
13
|
-
it { should have(1).item }
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'less than' do
|
17
|
-
subject { TodoItem.where(:score_points.lt 3) }
|
18
|
-
it { should have(2).items }
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'combine comparsions' do
|
22
|
-
subject { TodoItem.where(:score_points.gt(1), :due_date.lt(2.days.since.to_date)) }
|
23
|
-
|
24
|
-
it { should have(1).item }
|
25
|
-
its('first.score_points') { should be(2) }
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
#context 'Filtering with joins' do
|
31
|
-
# before do
|
32
|
-
# head = create(:todo_item, score_points: 10, due_date: Date.current)
|
33
|
-
# 3.times do |index|
|
34
|
-
# create(:todo_item, parent: head, score_points: index + 1, due_date: Date.current + index.days)
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
# context 'greater than' do
|
39
|
-
# subject { TodoItem.joins(:sub_tasks).where(:sub_tasks => {:id => 12}) }
|
40
|
-
# it { should have(1).item }
|
41
|
-
# its('first.parent') { should_not be(nil) }
|
42
|
-
# end
|
43
|
-
#end
|
44
|
-
end
|
data/spec/factories/todo_item.rb
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
|
4
|
-
#require 'support/active_record'
|
5
|
-
require 'active_model'
|
6
|
-
require 'active_record'
|
7
|
-
require 'factory_girl'
|
8
|
-
require 'rspec/rails/extensions/active_record/base'
|
9
|
-
|
10
|
-
require 'eel'
|
11
|
-
|
12
|
-
dirname = File.dirname(__FILE__)
|
13
|
-
Dir["#{dirname}/support/**/*.rb"].each { |i| require i.gsub("#{dirname}/", '') }
|
14
|
-
|
15
|
-
FactoryGirl.find_definitions
|
16
|
-
|
17
|
-
RSpec.configure do |config|
|
18
|
-
config.include FactoryGirl::Syntax::Methods
|
19
|
-
|
20
|
-
config.around do |example|
|
21
|
-
ActiveRecord::Base.transaction do
|
22
|
-
example.run
|
23
|
-
raise ActiveRecord::Rollback
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
2
|
-
|
3
|
-
ActiveRecord::Migration.create_table :todo_items do |t|
|
4
|
-
t.string :name, null: false
|
5
|
-
t.integer :score_points, null: false, default: 0
|
6
|
-
t.integer :parent_id
|
7
|
-
t.date :due_date
|
8
|
-
t.timestamps
|
9
|
-
end
|
10
|
-
|
11
|
-
class TodoItem < ActiveRecord::Base
|
12
|
-
validates :name, presence: true
|
13
|
-
validates :score_points, presence: true
|
14
|
-
|
15
|
-
belongs_to :parent, class_name: 'TodoItem'
|
16
|
-
has_many :sub_tasks, class_name: 'TodoItem', foreign_key: :parent_id, inverse_of: :parent
|
17
|
-
end
|