eel 0.0.1 → 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.
- data/.rbenv-version +1 -0
- data/Gemfile +5 -0
- data/Rakefile +3 -0
- data/eel.gemspec +2 -2
- data/lib/eel/active_record/query_extensions.rb +12 -3
- data/lib/eel/core_ext/symbol.rb +7 -2
- data/lib/eel/version.rb +1 -1
- data/spec/dsl/dsl_spec.rb +44 -0
- data/spec/factories/todo_item.rb +9 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/active_record.rb +17 -0
- metadata +29 -18
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p327
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/eel.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'eel/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = 'eel'
|
8
8
|
gem.version = Eel::VERSION
|
9
|
-
gem.authors = ['Ivan Efremov']
|
10
|
-
gem.email = ['st8998@gmail.com']
|
9
|
+
gem.authors = ['Ivan Efremov', 'Anatoly Lapshin']
|
10
|
+
gem.email = ['st8998@gmail.com', 'holywarez@gmail.com']
|
11
11
|
gem.description = %q{It is more like Squeel but without Squ}
|
12
12
|
gem.summary = %q{It is more like Squeel but without Squ}
|
13
13
|
gem.homepage = 'https://github.com/StrangeMood/eel'
|
@@ -4,8 +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.respond_to?(:expr) ? assign_context(a.expr) : a }
|
8
|
+
end
|
7
9
|
|
8
|
-
|
10
|
+
def reorder *args
|
11
|
+
return self if args.blank?
|
12
|
+
super *args.flatten.map { |a| a.respond_to?(:expr) ? assign_context(a.expr) : a }
|
9
13
|
end
|
10
14
|
|
11
15
|
def build_where(opts, other = [])
|
@@ -25,8 +29,13 @@ module Eel
|
|
25
29
|
private
|
26
30
|
|
27
31
|
def assign_context attr
|
28
|
-
if attr.is_a?(Arel::Attributes::Attribute)
|
29
|
-
attr.relation
|
32
|
+
if attr.is_a?(Arel::Attributes::Attribute)
|
33
|
+
case attr.relation
|
34
|
+
when Symbol
|
35
|
+
attr.relation = Arel::Table.new(attr.relation, table.engine)
|
36
|
+
when NilClass
|
37
|
+
attr.relation = table
|
38
|
+
end
|
30
39
|
end
|
31
40
|
attr
|
32
41
|
end
|
data/lib/eel/core_ext/symbol.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
class Symbol
|
2
2
|
|
3
3
|
delegate :gt, :gteq, :lt, :lteq,
|
4
|
-
:eq, :in,
|
4
|
+
:eq, :not_eq, :in, :not_in,
|
5
5
|
:desc, :asc,
|
6
6
|
to: :attr
|
7
7
|
|
8
|
+
def between *other
|
9
|
+
other = other.flatten
|
10
|
+
Arel::Nodes::Between.new(attr, Arel::Nodes::And.new(other))
|
11
|
+
end
|
12
|
+
|
8
13
|
def attr
|
9
14
|
attr = Arel::Attributes::Attribute.new
|
10
15
|
attr.name = self
|
@@ -16,7 +21,7 @@ class Symbol
|
|
16
21
|
when Class
|
17
22
|
val.arel_table
|
18
23
|
when Symbol
|
19
|
-
val
|
24
|
+
val
|
20
25
|
when String
|
21
26
|
val.classify.constantize
|
22
27
|
else
|
data/lib/eel/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
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/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
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
|
@@ -0,0 +1,17 @@
|
|
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
|
metadata
CHANGED
@@ -1,56 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ivan Efremov
|
9
|
+
- Anatoly Lapshin
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
16
|
-
|
16
|
+
name: activerecord
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
20
|
- - ~>
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '3.2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
26
|
none: false
|
22
|
-
requirement: !ruby/object:Gem::Requirement
|
23
27
|
requirements:
|
24
28
|
- - ~>
|
25
29
|
- !ruby/object:Gem::Version
|
26
30
|
version: '3.2'
|
27
|
-
none: false
|
28
|
-
name: activerecord
|
29
|
-
prerelease: false
|
30
31
|
- !ruby/object:Gem::Dependency
|
31
|
-
|
32
|
-
|
32
|
+
name: activesupport
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
33
35
|
requirements:
|
34
36
|
- - ~>
|
35
37
|
- !ruby/object:Gem::Version
|
36
38
|
version: '3.2'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
42
|
none: false
|
38
|
-
requirement: !ruby/object:Gem::Requirement
|
39
43
|
requirements:
|
40
44
|
- - ~>
|
41
45
|
- !ruby/object:Gem::Version
|
42
46
|
version: '3.2'
|
43
|
-
none: false
|
44
|
-
name: activesupport
|
45
|
-
prerelease: false
|
46
47
|
description: It is more like Squeel but without Squ
|
47
48
|
email:
|
48
49
|
- st8998@gmail.com
|
50
|
+
- holywarez@gmail.com
|
49
51
|
executables: []
|
50
52
|
extensions: []
|
51
53
|
extra_rdoc_files: []
|
52
54
|
files:
|
53
55
|
- .gitignore
|
56
|
+
- .rbenv-version
|
54
57
|
- Gemfile
|
55
58
|
- LICENSE.txt
|
56
59
|
- README.md
|
@@ -61,6 +64,10 @@ files:
|
|
61
64
|
- lib/eel/active_record/query_extensions.rb
|
62
65
|
- lib/eel/core_ext/symbol.rb
|
63
66
|
- 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
|
64
71
|
homepage: https://github.com/StrangeMood/eel
|
65
72
|
licenses: []
|
66
73
|
post_install_message:
|
@@ -68,21 +75,25 @@ rdoc_options: []
|
|
68
75
|
require_paths:
|
69
76
|
- lib
|
70
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
71
79
|
requirements:
|
72
80
|
- - ! '>='
|
73
81
|
- !ruby/object:Gem::Version
|
74
82
|
version: '0'
|
75
|
-
none: false
|
76
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
77
85
|
requirements:
|
78
86
|
- - ! '>='
|
79
87
|
- !ruby/object:Gem::Version
|
80
88
|
version: '0'
|
81
|
-
none: false
|
82
89
|
requirements: []
|
83
90
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.8.
|
91
|
+
rubygems_version: 1.8.23
|
85
92
|
signing_key:
|
86
93
|
specification_version: 3
|
87
94
|
summary: It is more like Squeel but without Squ
|
88
|
-
test_files:
|
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
|