biller_bot_resource 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17a99fdcc82deaf4fe33e71de9b3aec0bb5ea116
4
- data.tar.gz: e5643dee62d2ee1414d33b2d715bb4b66f68ba68
3
+ metadata.gz: 731e0a254c2530a5a067ce927d8f4e0831b23c40
4
+ data.tar.gz: 15b6118dcf428615f412ff2e0ad28f965796fd77
5
5
  SHA512:
6
- metadata.gz: 5f5295b254d889e4fc7547a664d01d674e4257dde70cf71e72e32d9cb4ea5591ae3619f50a927c53d2151fdb27938a21f3c9de775dd87f8963a1b2d3cab8a3bd
7
- data.tar.gz: 4b971651e7b962c6e7d3af252f7caf85bb7b0432d4f4ff5552a791b8846d20753f2b4c8e4c7237133f99bb41d01ed89e9075039f3d032317defcfcc60c771bfc
6
+ metadata.gz: d15d15776fd56c444ce2975ca1639f5a1ce07b4872a9301c85b91d340d1cd2738e0bcb0051c560fbdae8943cbc7324177cc69cb078a0fea34c6cb61e9e024354
7
+ data.tar.gz: 6fb65291c1b97293a3c7834d4076acb2a74e71dc0a99ef782c72cb9224cee30d617206a029c4ba24bdf476e6238a74d40f39d8dc92e49b5bcf092639298885cb
@@ -3,10 +3,10 @@ class BillerBotResource::Product < BillerBotResource::Resource
3
3
  class Context < BillerBotResource::Resource
4
4
  self.prefix = "/products/:product_id/"
5
5
 
6
- attr_accessor :product_id
6
+ attr_accessor :product
7
7
 
8
8
  def prefix_options
9
- { :product_id => product_id }
9
+ { :product_id => product.id }
10
10
  end
11
11
 
12
12
  ##
@@ -18,7 +18,7 @@ class BillerBotResource::Product < BillerBotResource::Resource
18
18
 
19
19
  # Propogate to all children too.
20
20
  contexts.each do |c|
21
- c.product_id = product_id
21
+ c.product = product
22
22
  c.force_persisted
23
23
  end
24
24
  end
@@ -29,7 +29,7 @@ class BillerBotResource::Product < BillerBotResource::Resource
29
29
  # @param [String] type The type of context to be searching for
30
30
  # @return [Array<BillerBotResource::Product::Context] The matching contexts
31
31
  def children_with_type(type)
32
- matches = contexts.select { |c| (c.type.downcase == type.to_s.downcase) }
32
+ contexts.select { |c| (c.type.downcase == type.to_s.downcase) }
33
33
  end
34
34
 
35
35
  ##
@@ -39,12 +39,40 @@ class BillerBotResource::Product < BillerBotResource::Resource
39
39
  def descendants_with_self
40
40
  [self, contexts.map(&:descendants_with_self)].flatten.uniq
41
41
  end
42
+
43
+ def parent
44
+ return nil unless product
45
+ product.contexts.each do |c|
46
+ r = c.with_child(self)
47
+ return r if r
48
+ end
49
+
50
+ nil
51
+ end
52
+
53
+ def with_child(context)
54
+ return self if contexts.include?(context)
55
+ contexts.each do |c|
56
+ result = c.with_child(context)
57
+ return result if result
58
+ end
59
+
60
+ nil
61
+ end
62
+
63
+ def parent_quantity
64
+ if parent && parent.quantity
65
+ parent.quantity
66
+ else
67
+ 0
68
+ end
69
+ end
42
70
  end
43
71
 
44
72
  def initialize(*args)
45
73
  super
46
74
  contexts.each do |c|
47
- c.product_id = id
75
+ c.product = self
48
76
  c.force_persisted # See comments on method
49
77
  end
50
78
  end
@@ -59,7 +87,7 @@ class BillerBotResource::Product < BillerBotResource::Resource
59
87
  end
60
88
 
61
89
  def context(id)
62
- context = all_contexts.select { |c| c.id.try(:to_i) == id.try(:to_i) }.first
90
+ context = all_contexts.select { |c| c.id.try(:to_i) == id.to_i }.first
63
91
  raise ActiveResource::ResourceNotFound.new(nil) if context.nil?
64
92
  context
65
93
  end
@@ -1,3 +1,3 @@
1
1
  module BillerBotResource
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biller_bot_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Seefeld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-30 00:00:00.000000000 Z
11
+ date: 2013-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource