active_cached_resource 0.2.1 → 0.2.2

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: c32ab653731518678eebe3383d4c0848301c09a0e0f3844cc66c9e1657794fb9
4
- data.tar.gz: c185462d895d9bc6721bbc186bed4db7bd251c77922a580cc39cc7051b5508e7
3
+ metadata.gz: ff5568ae59b708a8797b4a76940222c5b6e6203ae6914fcefcccae0b6fd4702e
4
+ data.tar.gz: 810e8446382d26728299806a427f865de4fbda34de6704ceb3a231163b471c0a
5
5
  SHA512:
6
- metadata.gz: 946a1421c6fa752430a073981b6e44753cefb32676d1c7cf34e939d056f6ec2aadd13a050b7a5390b392132394250262ed24daec6ba0fe2e59d7d455f90201b2
7
- data.tar.gz: fe1872444d09cad3405917a65b90a4317a9b6a02504cd83896f183aa28d8002a505d67b6903d39facfbdeb0f1e2334a6d50c80be85edb4debf7cf1534fa4871e
6
+ metadata.gz: 9c4e5b58ec0e1e9151c51e62e6760dd408098b68a01c634ca0ef62e2f999a6bb5c2d2a4961db0563a3d3a3490f9dcd6934c76a12e940233fd212a78fa6d34df4
7
+ data.tar.gz: b5d37c1863e51ef8aec7db5afebabe35a25d0aae60453a48ba61212f9348aea1dda4a1c43f0c00a5d80008d30170988bbf826eecc4e7fc74b7a5d978b63be67f
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveCachedResource
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
@@ -4,7 +4,7 @@ module ActiveResource::Associations::Builder
4
4
  class Association # :nodoc:
5
5
  # providing a Class-Variable, which will have a different store of subclasses
6
6
  class_attribute :valid_options
7
- self.valid_options = [:class_name]
7
+ self.valid_options = [:class_name, :foreign_key]
8
8
 
9
9
  # would identify subclasses of association
10
10
  class_attribute :macro
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pry-byebug" # IGNORE: This line is for debugging purposes and should be removed in production code.
3
4
  module ActiveResource::Associations
4
5
  module Builder
5
- autoload :Association, "active_resource/associations/builder/association"
6
- autoload :HasMany, "active_resource/associations/builder/has_many"
7
- autoload :HasOne, "active_resource/associations/builder/has_one"
8
- autoload :BelongsTo, "active_resource/associations/builder/belongs_to"
6
+ autoload :Association, "activeresource/lib/active_resource/associations/builder/association"
7
+ autoload :HasMany, "activeresource/lib/active_resource/associations/builder/has_many"
8
+ autoload :HasOne, "activeresource/lib/active_resource/associations/builder/has_one"
9
+ autoload :BelongsTo, "activeresource/lib/active_resource/associations/builder/belongs_to"
9
10
  end
10
11
 
11
12
 
@@ -148,9 +149,11 @@ module ActiveResource::Associations
148
149
  elsif attributes.include?(method_name)
149
150
  attributes[method_name]
150
151
  elsif !new_record?
151
- instance_variable_set(ivar_name, reflection.klass.find(:all, params: { "#{self.class.element_name}_id": self.id }))
152
+ # Association would be set on custom primary key if explicitly defined, otherwise use convention _id
153
+ assoc_key = self.class.custom_primary_key || "#{self.class.element_name}_id"
154
+ instance_variable_set(ivar_name, reflection.klass.find(:all, params: { assoc_key => self.id }))
152
155
  else
153
- instance_variable_set(ivar_name, reflection.klass.find(:all))
156
+ instance_variable_set(ivar_name, reflection.klass.none)
154
157
  end
155
158
  end
156
159
  end
@@ -672,6 +672,10 @@ module ActiveResource
672
672
  end
673
673
  end
674
674
 
675
+ def none
676
+ collection_parser.none
677
+ end
678
+
675
679
  # An instance of ActiveResource::Connection that is the base \connection to the remote service.
676
680
  # The +refresh+ parameter toggles whether or not the \connection is refreshed at every request
677
681
  # or not (defaults to <tt>false</tt>).
@@ -717,6 +721,10 @@ module ActiveResource
717
721
 
718
722
  attr_writer :primary_key
719
723
 
724
+ def custom_primary_key
725
+ @primary_key
726
+ end
727
+
720
728
  def primary_key
721
729
  if defined?(@primary_key)
722
730
  @primary_key
@@ -1226,6 +1234,10 @@ module ActiveResource
1226
1234
  load(attributes, false, persisted)
1227
1235
  end
1228
1236
 
1237
+ def [](key)
1238
+ public_send(key)
1239
+ end
1240
+
1229
1241
  # Returns a \clone of the resource that hasn't been assigned an +id+ yet and
1230
1242
  # is treated as a \new resource.
1231
1243
  #
@@ -6,12 +6,12 @@ require "active_support/inflector"
6
6
  module ActiveResource # :nodoc:
7
7
  class Collection # :nodoc:
8
8
  include Enumerable
9
- delegate :==, :[], :&, :*, :+, :-, :<=>, :all?, :any?, :as_json, :at, :assoc, :blank?, :bsearch, :bsearch_index,
10
- :collect, :combination, :compact, :count, :cycle, :deconstruct, :deep_dup, :dig, :difference, :drop,
9
+ delegate :==, :[], :&, :*, :+, :-, :<=>, :<<, :all?, :any?, :as_json, :at, :assoc, :blank?, :bsearch, :bsearch_index,
10
+ :collect, :combination, :compact, :concat, :count, :cycle, :deconstruct, :deep_dup, :dig, :difference, :drop,
11
11
  :drop_while, :each, :each_index, :empty?, :eql?, :excluding, :filter, :fifth, :find_index, :first,
12
12
  :flatten, :fourth, :hash, :include?, :including, :index, :inspect, :intersect?,
13
13
  :intersection, :join, :last, :length, :map, :max, :min, :minmax, :none?, :one?, :pack, :permutation,
14
- :pretty_print_cycle, :present?, :product, :reject, :repeated_combination, :repeated_permutation,
14
+ :pretty_print_cycle, :present?, :product, :push, :reject, :repeated_combination, :repeated_permutation,
15
15
  :rassoc, :reverse, :reverse_each, :rindex, :rotate, :sample, :second, :second_to_last, :select,
16
16
  :shelljoin, :shuffle, :size, :slice, :sort, :sum, :take, :take_while, :third, :third_to_last, :to,
17
17
  :to_a, :to_ary, :to_fs, :to_formatted_s, :to_h, :to_param, :to_query, :to_s, :to_sentence, :to_xml,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_cached_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Luis Urena
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
- rubygems_version: 3.6.8
139
+ rubygems_version: 3.7.0
140
140
  specification_version: 4
141
141
  summary: ActiveResource, but with a caching layer.
142
142
  test_files: []