rails_dynamic_associations 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 02f1e9739f27b665443124374994afc6729e4e8f
4
- data.tar.gz: f5d07be362c9b98969dfe4b5b0109f6b429f2c0f
3
+ metadata.gz: 4dccbe5a752726f57eb97a9f03323efb4907fe0e
4
+ data.tar.gz: bba3e032f0bdc486b0bed4290b16a79b2ca14a5b
5
5
  SHA512:
6
- metadata.gz: 5ee36ecaeee3642a97e3875c93c365e7323ac01ecc6fd7db0f2e67310eaf3a23aa61d9a0e351ee88b5c98f7de8d676f31fa456a1d992167dd8e37d4a9e9fd6ec
7
- data.tar.gz: fc3ce8c1acbdebba32efd429e06eb5fc0b3390fc72163eb28905730f0a6293f5e0222fd67b2d89b8045a87aa138157f7b43b105bb070a7581efda2e0a0422802
6
+ metadata.gz: 68b1fb01b76e4b128978fcd829089c6a683332fc8b8aa6b1617db4e9bc32732d6636ac8d3e29f4460919f44f91bcb89086df736e179fe9428f00ff42be5ff3e5
7
+ data.tar.gz: 0c4802a3cf276dac52c6d91d394741830bf8925b800207d94feb1905e2ba40f2a41a12221a4427d5c86b20ef5c871a141f3ad9bb853844f729d954c8caa63812
@@ -5,32 +5,32 @@ class Relation < ActiveRecord::Base
5
5
 
6
6
  delegate :name, to: :role, allow_nil: true
7
7
 
8
- RailsDynamicAssociations.directions.each &-> (attribute, direction) do
9
- scope "#{direction}_abstract", -> (object = nil) {
8
+ RailsDynamicAssociations.directions.each &-> (association, method) do
9
+ scope "#{method}_abstract", -> (object = nil) {
10
10
  if object then
11
- send direction, object
11
+ send method, object
12
12
  else
13
13
  all
14
14
  end.
15
- where "#{attribute}_id" => nil
15
+ where "#{association}_id" => nil
16
16
  }
17
17
 
18
- scope "#{direction}_general", -> {
19
- send("#{direction}_abstract").
20
- where "#{attribute}_type" => nil
18
+ scope "#{method}_general", -> {
19
+ send("#{method}_abstract").
20
+ where "#{association}_type" => nil
21
21
  }
22
22
 
23
- scope direction, -> (object) {
23
+ scope method, -> (object) {
24
24
  case object
25
25
  when nil then
26
26
  all
27
27
  when Symbol then
28
- send "#{direction}_#{object}"
28
+ send "#{method}_#{object}"
29
29
  when Class then
30
- where "#{attribute}_type" => object.base_class
30
+ where "#{association}_type" => object.base_class
31
31
  else
32
- where "#{attribute}_type" => object.class.base_class,
33
- "#{attribute}_id" => object.id
32
+ where "#{association}_type" => object.class.base_class,
33
+ "#{association}_id" => object.id
34
34
  end
35
35
  }
36
36
  end
data/app/models/role.rb CHANGED
@@ -13,11 +13,11 @@ class Role < ActiveRecord::Base
13
13
  }
14
14
 
15
15
  scope :in, -> (object) {
16
- where relations: { id: object.source_relations } # TODO: simplify
16
+ where relations: { id: Relation.to(object) } # TODO: simplify
17
17
  }
18
18
 
19
19
  scope :for, -> (subject) {
20
- where relations: { id: subject.target_relations } # TODO: simplify
20
+ where relations: { id: Relation.of(subject) } # TODO: simplify
21
21
  }
22
22
 
23
23
  def self.find_or_create_named *names
@@ -90,7 +90,7 @@ module RailsDynamicAssociations::ActiveRecord
90
90
  end
91
91
  else
92
92
  if target == self then
93
- RailsDynamicAssociations.self_referential_recursive[type].to_s
93
+ RailsDynamicAssociations.self_referential[type].to_s
94
94
  else
95
95
  target.name.split('::').reverse.join
96
96
  end
@@ -1,3 +1,3 @@
1
1
  module RailsDynamicAssociations
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_dynamic_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Senko