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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dd6c0a413bc426a0a22dee85cb7077ffb21c47fb77e5cf411a47478961002d1
4
- data.tar.gz: 5c7b93bcd554161bf4020f5f3d3cec8882d31ec0b9da86ef26b72b08f70d146d
3
+ metadata.gz: 4bb54c09be5bd01b84d55f0bb8e959e5ef1a5c7f6a13d4f6ed55089f901129b1
4
+ data.tar.gz: 20d17ac8e31e7866148b70d2983d2941bd298e4cd9fa6e94e5756e85a52a904d
5
5
  SHA512:
6
- metadata.gz: 04f3c99ff11c241b3a0915d06e4c32cf171bd31b18314ac23f7c2536ad8d35aefaac73bdcfe4cbb4c6476a04db3bfcf03fdbde902865ea8dc761671d9894efed
7
- data.tar.gz: b19fcf8ef79262680551b65f0dffe47d5c0cb2b1216d5c7c149dd7d7037067f3b5785dd87d2aa6d5ce0dc8d749d440f0864a6c4360b7bf1d30273475d42f0ebb
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('admins') { where(kind: 1) }
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 "admins" AS
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
- singleton_class.alias_method :unframed_all, :all
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
 
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Framing
3
- VERSION = "0.1.0-2"
3
+ VERSION = "0.1.0-3"
4
4
  end
5
5
  end
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.2
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-08 00:00:00.000000000 Z
11
+ date: 2019-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord