her 0.7.2 → 0.7.3

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: e3f3ebeacfc88f8ba6fbb3dc98cb7527975c8531
4
- data.tar.gz: c96e0c1b82ef1528529ac806a3d1b71e7e1aa434
3
+ metadata.gz: 87aaa3745246a66aad1a02e08921a10a4ffbd3af
4
+ data.tar.gz: ecd7f1c297037dabdb587d44c5fb002ab2445f09
5
5
  SHA512:
6
- metadata.gz: 71d3c48cf6fc0aa560e5349d695cc234d981602d721e9c6d59e3ce64ab2b4916af39ff360c691c5e1a3f341381d6d4fc158b19d17cacb6ea0fc7310f18fe9d70
7
- data.tar.gz: fdda014a8f9c66bf5f9f99b013022be531a798912a8e856d1b098fc846017e181237813849ebad7961d206ad799ab08948f47d64591a0b1955f3a9d3ff3cd476
6
+ metadata.gz: 5f794411479dbb0a4de3fb3d7fc7c33f916282c6d1b48cb463aa8ff2e12a58e421f06ab81377893958c4a5921a4f98a17952f2efd06a4529f070889903c4f05f
7
+ data.tar.gz: 410c1ac5f07cc3879a8b57c3674906a28ad57bd52a2beb5fb4b2c1470dada40171dac78c78fb41e0e8224a3a5ed2525029e1ba2659957706174c673316152be0
data/.travis.yml CHANGED
@@ -1,20 +1,15 @@
1
1
  language: ruby
2
2
 
3
+ sudo: false
4
+
3
5
  rvm:
4
6
  - 2.0.0
5
7
  - 1.9.3
6
- - 1.9.2
7
8
 
8
9
  gemfile:
10
+ - gemfiles/Gemfile.activemodel-4.2
9
11
  - gemfiles/Gemfile.activemodel-4.1
10
12
  - gemfiles/Gemfile.activemodel-4.0
11
13
  - gemfiles/Gemfile.activemodel-3.2.x
12
14
 
13
- matrix:
14
- exclude:
15
- - rvm: 1.9.2
16
- gemfile: gemfiles/Gemfile.activemodel-4.0
17
- - rvm: 1.9.2
18
- gemfile: gemfiles/Gemfile.activemodel-4.1
19
-
20
15
  script: "echo 'COME ON!' && bundle exec rake spec"
data/README.md CHANGED
@@ -476,6 +476,8 @@ end
476
476
  @user.changes # => {}
477
477
  ```
478
478
 
479
+ To update only the modified attributes specify `:send_only_modified_attributes => true` in the setup.
480
+
479
481
  ### Callbacks
480
482
 
481
483
  You can add *before* and *after* callbacks to your models that are triggered on specific actions. You can use symbols or blocks.
@@ -947,6 +949,7 @@ Most projects I know that use Her are internal or private projects but here’s
947
949
  * [crowdher](https://github.com/simonprev/crowdher)
948
950
  * [vodka](https://github.com/magnolia-fan/vodka)
949
951
  * [webistrano_cli](https://github.com/chytreg/webistrano_cli)
952
+ * [ASMALLWORLD](https://www.asmallworld.com)
950
953
 
951
954
  ## History
952
955
 
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => "../"
4
+
5
+ gem 'activemodel', '~> 4.2.0'
6
+ gem 'activesupport', '~> 4.2.0'
7
+ gem 'faraday', '~> 0.8.9'
data/her.gemspec CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency "fivemat", "~> 1.2"
24
24
  s.add_development_dependency "json", "~> 1.8"
25
25
 
26
- s.add_runtime_dependency "activemodel", ">= 3.0.0", "< 4.2"
27
- s.add_runtime_dependency "activesupport", ">= 3.0.0", "< 4.2"
26
+ s.add_runtime_dependency "activemodel", ">= 3.0.0", "<= 4.2"
27
+ s.add_runtime_dependency "activesupport", ">= 3.0.0", "<= 4.2"
28
28
  s.add_runtime_dependency "faraday", ">= 0.8", "< 1.0"
29
29
  s.add_runtime_dependency "multi_json", "~> 1.7"
30
30
  end
@@ -47,11 +47,12 @@ module Her
47
47
  attribute_value = @parent.attributes[@name]
48
48
  return @opts[:default].try(:dup) if @parent.attributes.include?(@name) && (attribute_value.nil? || !attribute_value.nil? && attribute_value.empty?) && @params.empty?
49
49
 
50
- if @parent.attributes[@name].blank? || @params.any?
51
- path = build_association_path lambda { "#{@parent.request_path(@params)}#{@opts[:path]}" }
52
- @klass.get(path, @params)
53
- else
54
- @parent.attributes[@name]
50
+ return @cached_result unless @params.any? || @cached_result.nil?
51
+ return @parent.attributes[@name] unless @params.any? || @parent.attributes[@name].blank?
52
+
53
+ path = build_association_path lambda { "#{@parent.request_path(@params)}#{@opts[:path]}" }
54
+ @klass.get(path, @params).tap do |result|
55
+ @cached_result = result unless @params.any?
55
56
  end
56
57
  end
57
58
 
@@ -76,12 +76,13 @@ module Her
76
76
  data_key_value = @parent.attributes[@opts[:data_key].to_sym]
77
77
  return @opts[:default].try(:dup) if (@parent.attributes.include?(@name) && @parent.attributes[@name].nil? && @params.empty?) || (@parent.persisted? && foreign_key_value.blank? && data_key_value.blank?)
78
78
 
79
- if @parent.attributes[@name].blank? || @params.any?
80
- path_params = @parent.attributes.merge(@params.merge(@klass.primary_key => foreign_key_value))
81
- path = build_association_path lambda { @klass.build_request_path(path_params) }
82
- @klass.get(path, @params)
83
- else
84
- @parent.attributes[@name]
79
+ return @cached_result unless @params.any? || @cached_result.nil?
80
+ return @parent.attributes[@name] unless @params.any? || @parent.attributes[@name].blank?
81
+
82
+ path_params = @parent.attributes.merge(@params.merge(@klass.primary_key => foreign_key_value))
83
+ path = build_association_path lambda { @klass.build_request_path(path_params) }
84
+ @klass.get(path, @params).tap do |result|
85
+ @cached_result = result if @params.blank?
85
86
  end
86
87
  end
87
88
 
data/lib/her/model.rb CHANGED
@@ -43,8 +43,6 @@ module Her
43
43
  include ActiveModel::Validations::Callbacks
44
44
  include ActiveModel::Conversion
45
45
  include ActiveModel::Dirty
46
- include ActiveModel::Naming
47
- include ActiveModel::Translation
48
46
 
49
47
  # Class methods
50
48
  included do
@@ -63,6 +61,9 @@ module Her
63
61
  store_response_errors :response_errors
64
62
  store_metadata :metadata
65
63
 
64
+ # Include ActiveModel naming methods
65
+ extend ActiveModel::Translation
66
+
66
67
  # Configure ActiveModel callbacks
67
68
  extend ActiveModel::Callbacks
68
69
  define_model_callbacks :create, :update, :save, :find, :destroy, :initialize
data/lib/her/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Her
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.3"
3
3
  end
@@ -137,6 +137,7 @@ describe Her::Model::Associations do
137
137
  let(:user_with_included_data_after_create) { Foo::User.create }
138
138
  let(:user_with_included_data_after_save_existing) { Foo::User.save_existing(5, :name => "Clancy Brown") }
139
139
  let(:user_with_included_data_after_destroy) { Foo::User.new(:id => 5).destroy }
140
+ let(:comment_without_included_parent_data) { Foo::Comment.new(:id => 7, :user_id => 1) }
140
141
 
141
142
  it "maps an array of included data through has_many" do
142
143
  @user_with_included_data.comments.first.should be_a(Foo::Comment)
@@ -149,6 +150,14 @@ describe Her::Model::Associations do
149
150
  @user_with_included_data.comments.first.user.object_id.should == @user_with_included_data.object_id
150
151
  end
151
152
 
153
+ it "does fetch the parent models data only once" do
154
+ comment_without_included_parent_data.user.object_id.should == comment_without_included_parent_data.user.object_id
155
+ end
156
+
157
+ it "does fetch the parent models data that was cached if called with parameters" do
158
+ comment_without_included_parent_data.user.object_id.should_not == comment_without_included_parent_data.user.where(:a => 2).object_id
159
+ end
160
+
152
161
  it "uses the given inverse_of key to set the parent model" do
153
162
  @user_with_included_data.posts.first.admin.object_id.should == @user_with_included_data.object_id
154
163
  end
@@ -164,6 +173,14 @@ describe Her::Model::Associations do
164
173
  @user_with_included_data.comments.where(:foo_id => 1).length.should == 1
165
174
  end
166
175
 
176
+ it "fetches data that was not included through has_many only once" do
177
+ @user_without_included_data.comments.first.object_id.should == @user_without_included_data.comments.first.object_id
178
+ end
179
+
180
+ it "fetches data that was cached through has_many if called with parameters" do
181
+ @user_without_included_data.comments.first.object_id.should_not == @user_without_included_data.comments.where(:foo_id => 1).first.object_id
182
+ end
183
+
167
184
  it "maps an array of included data through has_one" do
168
185
  @user_with_included_data.role.should be_a(Foo::Role)
169
186
  @user_with_included_data.role.object_id.should == @user_with_included_data.role.object_id
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: her
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-09 00:00:00.000000000 Z
11
+ date: 2014-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -87,7 +87,7 @@ dependencies:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: 3.0.0
90
- - - "<"
90
+ - - "<="
91
91
  - !ruby/object:Gem::Version
92
92
  version: '4.2'
93
93
  type: :runtime
@@ -97,7 +97,7 @@ dependencies:
97
97
  - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: 3.0.0
100
- - - "<"
100
+ - - "<="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '4.2'
103
103
  - !ruby/object:Gem::Dependency
@@ -107,7 +107,7 @@ dependencies:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: 3.0.0
110
- - - "<"
110
+ - - "<="
111
111
  - !ruby/object:Gem::Version
112
112
  version: '4.2'
113
113
  type: :runtime
@@ -117,7 +117,7 @@ dependencies:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
119
  version: 3.0.0
120
- - - "<"
120
+ - - "<="
121
121
  - !ruby/object:Gem::Version
122
122
  version: '4.2'
123
123
  - !ruby/object:Gem::Dependency
@@ -174,6 +174,7 @@ files:
174
174
  - gemfiles/Gemfile.activemodel-3.2.x
175
175
  - gemfiles/Gemfile.activemodel-4.0
176
176
  - gemfiles/Gemfile.activemodel-4.1
177
+ - gemfiles/Gemfile.activemodel-4.2
177
178
  - her.gemspec
178
179
  - lib/her.rb
179
180
  - lib/her/api.rb