plain_model 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/plain_model/query_builder.rb +2 -2
- data/lib/plain_model/querying/base.rb +10 -22
- data/lib/plain_model/querying/except.rb +8 -5
- data/lib/plain_model/querying/includes.rb +12 -11
- data/lib/plain_model/querying/where.rb +12 -11
- data/lib/plain_model/querying/with_model.rb +11 -11
- data/lib/plain_model/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7edc77ecf12c7fe60433f63f23d795b49d99159c3565d848e49cc48b17ebb26
|
4
|
+
data.tar.gz: a565e4f7f13b9d8a3974d56a2da1f8ed8956bb8af9f5b57d841d43c1be7c0940
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 799deefe0bc47e69a0a2ac89c01f4e2e4c1950b4f06f4edf4248d7aac47c79bef07a3a18ce96bb16cbf17a8798d55a5568a62f3ee02e36d1b1b71e69e7c15f51
|
7
|
+
data.tar.gz: 2ece3a004d52ab5dc6af1bc7b4b03c8b5e8549926cd9f6a1498550e23241d118ba7edae3904489efcd707754119476d0b59efec1104e0839328f25c494c7b9bd
|
@@ -9,9 +9,9 @@ require_relative 'querying/includes'
|
|
9
9
|
module PlainModel
|
10
10
|
class QueryBuilder
|
11
11
|
include PlainModel::Querying::Base
|
12
|
-
include PlainModel::Querying::WithModel
|
13
|
-
include PlainModel::Querying::Except
|
14
12
|
include PlainModel::Querying::Where
|
15
13
|
include PlainModel::Querying::Includes
|
14
|
+
include PlainModel::Querying::Except
|
15
|
+
include PlainModel::Querying::WithModel
|
16
16
|
end
|
17
17
|
end
|
@@ -10,25 +10,19 @@ module PlainModel
|
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
|
12
12
|
included do
|
13
|
-
class_attribute :chainable_methods, instance_accessor: false, default: []
|
14
|
-
|
15
|
-
class_attribute :result_methods,
|
16
|
-
instance_accessor: false,
|
17
|
-
default: [:to_a, :first, :last, :each, :collect, :map, :select, :detect]
|
18
|
-
|
19
13
|
extend Forwardable
|
20
|
-
|
21
|
-
instance_delegate [:first, :last, :each, :collect, :map, :
|
22
|
-
private :
|
23
|
-
|
24
|
-
def initialize(*args)
|
25
|
-
@values = {}
|
26
|
-
super(*args)
|
27
|
-
end
|
14
|
+
attr_accessor :values
|
15
|
+
instance_delegate [:first, :last, :each, :collect, :map, :filter, :detect] => :to_a
|
16
|
+
private :_records
|
17
|
+
end
|
28
18
|
|
29
|
-
|
19
|
+
def initialize(*args)
|
20
|
+
@values = initial_values
|
21
|
+
super(*args)
|
22
|
+
end
|
30
23
|
|
31
|
-
|
24
|
+
def initial_values
|
25
|
+
{}
|
32
26
|
end
|
33
27
|
|
34
28
|
def to_a
|
@@ -47,12 +41,6 @@ module PlainModel
|
|
47
41
|
[]
|
48
42
|
end
|
49
43
|
|
50
|
-
def _within_new_instance(&block)
|
51
|
-
new_instance = dup
|
52
|
-
new_instance.instance_exec(&block)
|
53
|
-
new_instance
|
54
|
-
end
|
55
|
-
|
56
44
|
def _records
|
57
45
|
raise NotImplementedError, "implement #_records private method in #{self.class}"
|
58
46
|
end
|
@@ -11,14 +11,17 @@ module PlainModel
|
|
11
11
|
# @param keys [Array<Symbol>] values keys that you want to exclude from query
|
12
12
|
# @return new instance with applied changes
|
13
13
|
def except(*keys)
|
14
|
-
|
15
|
-
self.values = values.except(*keys)
|
16
|
-
end
|
14
|
+
dup.except!(*keys)
|
17
15
|
end
|
18
16
|
|
19
|
-
|
20
|
-
|
17
|
+
# Chain method
|
18
|
+
# @param keys [Array<Symbol>] values keys that you want to exclude from query
|
19
|
+
# @return new instance with applied changes
|
20
|
+
def except!(*keys)
|
21
|
+
self.values = values.except(*keys)
|
22
|
+
self
|
21
23
|
end
|
24
|
+
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
@@ -9,23 +9,24 @@ module PlainModel
|
|
9
9
|
module Includes
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
|
12
|
-
def
|
13
|
-
super
|
14
|
-
values[:includes] = {}
|
15
|
-
end
|
16
|
-
|
17
|
-
included do
|
18
|
-
self.chainable_methods += [:includes]
|
12
|
+
def initial_values
|
13
|
+
super.merge includes: {}
|
19
14
|
end
|
20
15
|
|
21
16
|
# Chain method
|
22
17
|
# @param names [Array<Symbol,Hash>] - names of includes with optional tail hash for nested includes
|
23
18
|
# @return new instance with applied changes
|
24
19
|
def includes(*names)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
dup.includes!(*names)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Chain method
|
24
|
+
# @param names [Array<Symbol,Hash>] - names of includes with optional tail hash for nested includes
|
25
|
+
# @return current instance with applied changes
|
26
|
+
def includes!(*names)
|
27
|
+
new_includes = ::PlainModel::MergeIncludes.new(values[:includes]).merge(names)
|
28
|
+
values[:includes] = new_includes
|
29
|
+
self
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -7,22 +7,23 @@ module PlainModel
|
|
7
7
|
module Where
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
-
def
|
11
|
-
super
|
12
|
-
values[:where] = {}
|
10
|
+
def initial_values
|
11
|
+
super.merge where: []
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
# Chain method
|
15
|
+
# @param conditions [Array]
|
16
|
+
# @return new instance with applied changes
|
17
|
+
def where(*conditions)
|
18
|
+
dup.where!(*conditions)
|
17
19
|
end
|
18
20
|
|
19
21
|
# Chain method
|
20
|
-
# @param conditions [
|
21
|
-
# @return
|
22
|
-
def where(conditions)
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
# @param conditions [Array]
|
23
|
+
# @return current instance with applied changes
|
24
|
+
def where!(*conditions)
|
25
|
+
values[:where] = (values[:where] + conditions).uniq
|
26
|
+
self
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
@@ -7,24 +7,24 @@ module PlainModel
|
|
7
7
|
module WithModel
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
+
included do
|
11
|
+
attr_reader :model_class
|
12
|
+
private :_records
|
13
|
+
end
|
14
|
+
|
10
15
|
def initialize(model_class, *args)
|
11
16
|
@model_class = model_class
|
12
17
|
super(*args)
|
13
18
|
end
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def dup_args
|
19
|
-
[model_class]
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
20
|
+
def dup_args
|
21
|
+
super + [model_class]
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
24
|
+
def _records
|
25
|
+
model_class._records(values)
|
27
26
|
end
|
27
|
+
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/lib/plain_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plain_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Talakevich
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -132,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
|
-
|
136
|
-
rubygems_version: 2.7.9
|
135
|
+
rubygems_version: 3.0.4
|
137
136
|
signing_key:
|
138
137
|
specification_version: 4
|
139
138
|
summary: Plan Old Ruby Object with ORM and query support.
|