active_record-framing 0.1.0.pre.2 → 0.1.0.pre.3
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.
- checksums.yaml +4 -4
- data/README.md +24 -3
- data/lib/active_record/framing/core_extension.rb +2 -2
- data/lib/active_record/framing/relation.rb +0 -6
- data/lib/active_record/framing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bb54c09be5bd01b84d55f0bb8e959e5ef1a5c7f6a13d4f6ed55089f901129b1
|
4
|
+
data.tar.gz: 20d17ac8e31e7866148b70d2983d2941bd298e4cd9fa6e94e5756e85a52a904d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ba3bbbb8ebc8eeaabdbcabc927ed2a2358922c91286f99007a99354e38165f6f62a33c56030b2e3cf1e3457864793feed1a9277c1eacd4f52dbf55d1cf76463
|
7
|
+
data.tar.gz: 6dbd8f819768e3e90ce8b9777d7280fa793cbe276a9af84da4fed7ab961b4fba1cc284e7cdb337c07372c8d623d4b2c0db43f5cdc3854b74e379da0a5de85db1
|
data/README.md
CHANGED
@@ -51,15 +51,36 @@ SELECT "users".* FROM "users"
|
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
class Admin < User
|
54
|
-
default_frame
|
54
|
+
default_frame { where(arel_table[:kind].eq(1)) }
|
55
55
|
# ...
|
56
56
|
end
|
57
57
|
```
|
58
58
|
|
59
|
+
Note: In `ActiveRecord` versions less than `5.2` (Arel `9.0`), `default_frames` where clauses must be constructed with `arel` (`arel_table[:column]` etc) for values other than `nil`, `true`, and `false`. This is due to a limitation with what ActiveRecord calls "bind values" (beyond the scope of this document).
|
60
|
+
|
59
61
|
Afterwards, `Admin.all.to_sql` yields
|
60
62
|
```sql
|
61
|
-
WITH "
|
62
|
-
(SELECT "users".* )
|
63
|
+
WITH "users" AS
|
64
|
+
(SELECT "users".* FROM "users" WHERE "users"."kind" = 1)
|
65
|
+
```
|
66
|
+
|
67
|
+
Similar to how `named_scopes` work in `ActiveRecord`, frames can be named:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
class User < ActiveRecord::Base
|
71
|
+
frame :admin, -> { where(arel_table[:kind].eq(1)) }
|
72
|
+
# ...
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
Named frames are accessed through assigned consts under the original class. This helps avoid collision with scopes, and helps indicate the mutual exclusivity of frames (by design).
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
User::Admin.all.to_sql
|
80
|
+
# =>
|
81
|
+
# WITH "admin/users" AS
|
82
|
+
# (SELECT "users".* FROM "users" WHERE "users".kind = 1)
|
83
|
+
# SELECT "admin/users".* FROM "admin/users"
|
63
84
|
```
|
64
85
|
|
65
86
|
## Development
|
@@ -6,8 +6,8 @@ module ActiveRecord
|
|
6
6
|
module Framing
|
7
7
|
|
8
8
|
def self.prepended(subclass)
|
9
|
-
subclass.class_eval do
|
10
|
-
|
9
|
+
subclass.singleton_class.class_eval do
|
10
|
+
alias_method :unframed_all, :all
|
11
11
|
end
|
12
12
|
|
13
13
|
subclass.include Default
|
@@ -38,17 +38,11 @@ module ActiveRecord
|
|
38
38
|
source.left.name.to_s # TODO: Need to_s?
|
39
39
|
end
|
40
40
|
|
41
|
-
# scopes = klass.reflections.slice(*join_names).values.inject(Hash.new) do |collector, assoc|
|
42
41
|
# NOTE: We cannot early exclude associations because some associations are different from their table names
|
43
42
|
klass.reflect_on_all_associations.each do |assoc|
|
44
|
-
# collector.merge(assoc.klass.default_scopes) if join_names.include?(assoc.table_name)
|
45
|
-
# (collector[assoc.klass] ||= Set.new).merge(assoc.klass.default_scopes) if join_names.include?(assoc.table_name) && assoc.klass.default_scopes.any?
|
46
43
|
if join_names.include?(assoc.table_name) && assoc.klass.default_frames.any? && assoc_default_frame = assoc.klass.send(:build_default_frame)
|
47
44
|
merge!(assoc_default_frame)
|
48
|
-
# collector[assoc_default_frame.table_name] ||= assoc_default_frame
|
49
45
|
end
|
50
|
-
|
51
|
-
# collector
|
52
46
|
end
|
53
47
|
end
|
54
48
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-framing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.
|
4
|
+
version: 0.1.0.pre.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Stevens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|