active_remote 1.5.9 → 1.6.0

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: 528f82335b1b30d9baad0fb5f8039e6e7b5773b1
4
- data.tar.gz: e85d2753fe773ff549c0c733f7227ec1600240bf
3
+ metadata.gz: e660e679338d45a8815db30aed43a7f2376d3db3
4
+ data.tar.gz: bf4afbe98337b384a369df5cb5d4b7ad19d3d009
5
5
  SHA512:
6
- metadata.gz: f9330f045952e311261eb5b2c974a62587069651cda046b97f8a11e65fe3d4eb899d2a304ec45adf407062c7fc000184e34ada6d75c0995b0c4f06b367d75bdd
7
- data.tar.gz: b1b998e8fb3d6ab724546f466b201f890a0a6eb3f60d154d72a5dbdec41ab6e8276e9ff165dabe158f184c9de52beef4efb1ef8a9fc6a0c6508b262f93e3051a
6
+ metadata.gz: 5bfb0fb12ba5dd76c11fa9bebea904bdad40c74c6be49cf23556589a687bcfd01e51e1ef08ddf41a520bdbc30fab514d05a22e81cdb0b9cb02d7ceba1a427cf0
7
+ data.tar.gz: 3a95c65136b76bc0b0e99b23a5ad781f898d28075f4516bf38c3121f0717846413a7fe5bc284fd4e309ea0d6326bc8e68f998daf8f7c44ce8f4075b318b65adc
@@ -2,7 +2,7 @@ module ActiveRemote
2
2
  module Association
3
3
  def self.included(klass)
4
4
  klass.class_eval do
5
- extend ActiveRemote::Association::ClassMethods
5
+ extend ::ActiveRemote::Association::ClassMethods
6
6
  end
7
7
  end
8
8
 
@@ -3,6 +3,7 @@ require 'active_remote/attributes'
3
3
  require 'active_remote/bulk'
4
4
  require 'active_remote/dirty'
5
5
  require 'active_remote/dsl'
6
+ require 'active_remote/integration'
6
7
  require 'active_remote/persistence'
7
8
  require 'active_remote/publication'
8
9
  require 'active_remote/rpc'
@@ -19,6 +20,7 @@ module ActiveRemote
19
20
  include ::ActiveRemote::Attributes
20
21
  include ::ActiveRemote::Bulk
21
22
  include ::ActiveRemote::DSL
23
+ include ::ActiveRemote::Integration
22
24
  include ::ActiveRemote::Persistence
23
25
  include ::ActiveRemote::Publication
24
26
  include ::ActiveRemote::RPC
@@ -4,8 +4,8 @@ module ActiveRemote
4
4
  module Bulk
5
5
  def self.included(klass)
6
6
  klass.class_eval do
7
- extend ActiveRemote::Bulk::ClassMethods
8
- include ActiveRemote::Persistence
7
+ extend ::ActiveRemote::Bulk::ClassMethods
8
+ include ::ActiveRemote::Persistence
9
9
  end
10
10
  end
11
11
 
@@ -4,8 +4,8 @@ module ActiveRemote
4
4
  module DSL
5
5
  def self.included(klass)
6
6
  klass.class_eval do
7
- extend ActiveRemote::DSL::ClassMethods
8
- include ActiveRemote::DSL::InstanceMethods
7
+ extend ::ActiveRemote::DSL::ClassMethods
8
+ include ::ActiveRemote::DSL::InstanceMethods
9
9
  end
10
10
  end
11
11
 
@@ -0,0 +1,52 @@
1
+ module ActiveRemote
2
+ module Integration
3
+ def self.included(klass)
4
+ klass.class_eval do
5
+ unless singleton_methods.include?(:cache_timestamp_format)
6
+ ##
7
+ # :singleton-method:
8
+ # Indicates the format used to generate the timestamp format in the cache key.
9
+ # This is +:number+, by default.
10
+ #
11
+ def self.cache_timestamp_format
12
+ :number
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+
19
+ ##
20
+ # Returns a String, which can be used for constructing an URL to this
21
+ # object. The default implementation returns this record's guid as a String,
22
+ # or nil if this record's unsaved.
23
+ #
24
+ # user = User.search(:name => 'Phusion')
25
+ # user.to_param # => "GUID-1"
26
+ #
27
+ def to_param
28
+ self[:guid] && self[:guid].to_s
29
+ end
30
+
31
+ ##
32
+ # Returns a cache key that can be used to identify this record.
33
+ #
34
+ # ==== Examples
35
+ #
36
+ # Product.new.cache_key # => "products/new"
37
+ # Product.search(:guid => "derp-5").cache_key # => "products/derp-5" (updated_at not available)
38
+ # Person.search(:guid => "derp-5").cache_key # => "people/derp-5-20071224150000" (updated_at available)
39
+ #
40
+ def cache_key
41
+ case
42
+ when new_record? then
43
+ "#{self.class.name.underscore}/new"
44
+ when timestamp = self[:updated_at] then
45
+ timestamp = timestamp.utc.to_s(self.class.cache_timestamp_format)
46
+ "#{self.class.name.underscore}/#{self.to_param}-#{timestamp}"
47
+ else
48
+ "#{self.class.name.underscore}/#{self.to_param}"
49
+ end
50
+ end
51
+ end
52
+ end
@@ -4,9 +4,9 @@ module ActiveRemote
4
4
  module Persistence
5
5
  def self.included(klass)
6
6
  klass.class_eval do
7
- extend ActiveRemote::Persistence::ClassMethods
8
- include ActiveRemote::Persistence::InstanceMethods
9
- include ActiveRemote::RPC
7
+ extend ::ActiveRemote::Persistence::ClassMethods
8
+ include ::ActiveRemote::Persistence::InstanceMethods
9
+ include ::ActiveRemote::RPC
10
10
 
11
11
  # Allow users to create callbacks around a `save` call.
12
12
  #
@@ -1,3 +1,3 @@
1
1
  module ActiveRemote
2
- VERSION = "1.5.9"
2
+ VERSION = "1.6.0"
3
3
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::ActiveRemote::Integration do
4
+ let(:guid) { "GUID-derp" }
5
+ subject { Tag.new(:guid => guid) }
6
+
7
+ context "#to_param" do
8
+ # API
9
+ specify { subject.should respond_to(:to_param) }
10
+
11
+ it "returns the guid if the guid is present (by default)" do
12
+ subject.to_param.should eq(guid)
13
+ end
14
+ end
15
+
16
+ context "#cache_key" do
17
+ # API
18
+ specify { subject.should respond_to(:cache_key) }
19
+
20
+ it "sets 'new' as the identifier when the record has not been persisted" do
21
+ subject.should_receive(:new_record?).and_return(true)
22
+ subject.cache_key.should match(/tag\/new/)
23
+ end
24
+
25
+ it "sets the cache_key to the class/guid as a default" do
26
+ subject.should_receive(:new_record?).and_return(false)
27
+ subject.cache_key.should eq("tag/#{guid}")
28
+ end
29
+
30
+ it "adds the 'updated_at' attribute to the cache_key if updated_at is present" do
31
+ twenty_o_one_one = subject[:updated_at] = DateTime.new(2001, 01, 01)
32
+ subject.should_receive(:new_record?).and_return(false)
33
+ subject.cache_key.should eq("tag/#{guid}-#{twenty_o_one_one.to_s(:number)}")
34
+ subject[:updated_at] = nil
35
+ end
36
+ end
37
+ end
@@ -76,7 +76,7 @@ describe ActiveRemote::Search do
76
76
 
77
77
  describe "#reload" do
78
78
  let(:args) { { :guid => 'foo' } }
79
- let(:attributes) { HashWithIndifferentAccess.new(:guid => 'foo', :name => 'bar') }
79
+ let(:attributes) { HashWithIndifferentAccess.new(:guid => 'foo', :name => 'bar', :updated_at => nil) }
80
80
 
81
81
  subject { Tag.new(args) }
82
82
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveRemote::Serializers::JSON do
4
4
  describe "#as_json" do
5
- let(:attributes) { { :guid => 'foo', :name => 'bar' } }
5
+ let(:attributes) { { :guid => 'foo', :name => 'bar', :updated_at => nil } }
6
6
  let(:serializable_attributes) { { "tag" => attributes.stringify_keys } }
7
7
 
8
8
  subject { Tag.new(attributes) }
@@ -8,5 +8,6 @@ class Tag < ::ActiveRemote::Base
8
8
 
9
9
  attribute :guid
10
10
  attribute :name
11
+ attribute :updated_at
11
12
 
12
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.9
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hutchison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-03 00:00:00.000000000 Z
11
+ date: 2013-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_attr
@@ -146,6 +146,7 @@ files:
146
146
  - lib/active_remote/dirty.rb
147
147
  - lib/active_remote/dsl.rb
148
148
  - lib/active_remote/errors.rb
149
+ - lib/active_remote/integration.rb
149
150
  - lib/active_remote/persistence.rb
150
151
  - lib/active_remote/publication.rb
151
152
  - lib/active_remote/rpc.rb
@@ -164,6 +165,7 @@ files:
164
165
  - spec/lib/active_remote/bulk_spec.rb
165
166
  - spec/lib/active_remote/dirty_spec.rb
166
167
  - spec/lib/active_remote/dsl_spec.rb
168
+ - spec/lib/active_remote/integration_spec.rb
167
169
  - spec/lib/active_remote/persistence_spec.rb
168
170
  - spec/lib/active_remote/publication_spec.rb
169
171
  - spec/lib/active_remote/rpc_spec.rb
@@ -220,6 +222,7 @@ test_files:
220
222
  - spec/lib/active_remote/bulk_spec.rb
221
223
  - spec/lib/active_remote/dirty_spec.rb
222
224
  - spec/lib/active_remote/dsl_spec.rb
225
+ - spec/lib/active_remote/integration_spec.rb
223
226
  - spec/lib/active_remote/persistence_spec.rb
224
227
  - spec/lib/active_remote/publication_spec.rb
225
228
  - spec/lib/active_remote/rpc_spec.rb