calculable_attrs 0.0.7 → 0.0.8

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: 2acc8c2bd3bd3883d2a9938d44758b331dfa0507
4
- data.tar.gz: f3038c8670179d675b46885afc0672ea1cdce58f
3
+ metadata.gz: 2cb90fc5396803596c76b7179e003580f5325a57
4
+ data.tar.gz: a6d5fa763da75d215749063635f0aec3a787c5ea
5
5
  SHA512:
6
- metadata.gz: 79f265e0de6c7a2f8c9209cd06fe64b384e06d4eb968c143515a790889588a9a8e8f866f819da34cb0fdc82a35dbb86341f8166d1066707e9d296ca6a8c24258
7
- data.tar.gz: 2df9df59d367ea0edc4950bcf421819b3447a6acf794af62b7ffc3f7f6a973a00f74e0362cf7acb0d8d9ad6de621f432aca70d59f9fe0dea54dbe63ef0d1c5aa
6
+ metadata.gz: 8cd92421d55e7e32b2f742721851f7d2285165a5be5db5066195669e7d03bfa31e78aa767a4b224ade25939ed3b0b48491d7ddad984a35d1bfe45a280206eeed
7
+ data.tar.gz: 07fc087b96843bc8be86ff3053a1f06226c2806a86b721a1722e1fb790ecdeba34917b236ac2a0ca998ff298f0527f0a3217e643542ded97a78870ce4e9aca7b
@@ -26,6 +26,10 @@ module CalculableAttrs::ActiveRecord::Base
26
26
  def calculable_attrs
27
27
  calculable_attrs_calculators.keys
28
28
  end
29
+
30
+ def calculable_attr_calculator(attr)
31
+ calculable_attrs_calculators[attr]
32
+ end
29
33
  end
30
34
 
31
35
  def self.included(base)
@@ -1,6 +1,6 @@
1
1
  class CalculableAttrs::Calculator
2
2
  CALCULABLE_FOREIGN_KEY = '__calculable_id__'
3
- attr_reader :attrs
3
+ attr_reader :attrs, :relation, :foreign_key
4
4
 
5
5
  def initialize(relation: nil, foreign_key: nil, attributes: nil)
6
6
  @relation = relation
@@ -40,6 +40,14 @@ class CalculableAttrs::Calculator
40
40
  calculate(attrs, id)
41
41
  end
42
42
 
43
+ def base_query(attrs, id)
44
+ scoped_relation(id).select(build_select(attrs))
45
+ end
46
+
47
+ def scoped_relation(id)
48
+ @relation.call.where( @foreign_key => id)
49
+ end
50
+
43
51
  private
44
52
 
45
53
  def save_attribute_value(name, value)
@@ -58,9 +66,6 @@ class CalculableAttrs::Calculator
58
66
  end
59
67
  end
60
68
 
61
- def base_query(attrs, id)
62
- @relation.call.select(build_select(attrs)).where( @foreign_key => id)
63
- end
64
69
 
65
70
  def normalize_many_records_result(ids, attrs, records)
66
71
  normalized = {}
@@ -1,3 +1,3 @@
1
1
  module CalculableAttrs
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calculable_attrs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Sharkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-25 00:00:00.000000000 Z
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord