remotely 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94c992b78a682bc69db2b902ee75a6b5b9fb5e58
4
+ data.tar.gz: 64f00a68922e910d14f91f19bbd6970a9a0f35e2
5
+ SHA512:
6
+ metadata.gz: d43b00413570a0265d41c9259d4a834478eed74ca166f3a635037ca7cb39dc3efc344d20793f7b2a5f37d6f9cdf2ff710402411a862bb78f0903c8c391452fb8
7
+ data.tar.gz: 9f4d3ac58a62e7c1ddded8927f1326959c52fe5320d0c8cfca380ebbeeccfbb14d9194804674fb21f85f6b2bfb6b2d25a94a481e7871414d05145dbcc1957b37
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  .config
6
6
  .yardoc
7
7
  Gemfile.lock
8
+ gemfiles/*.gemfile.lock
8
9
  InstalledFiles
9
10
  _yardoc
10
11
  coverage
@@ -1,8 +1,22 @@
1
+ sudo: false
1
2
  language: ruby
3
+ script: rspec spec
4
+
5
+ gemfile:
6
+ - gemfiles/rails32.gemfile
7
+ - gemfiles/rails41.gemfile
8
+ - gemfiles/rails42.gemfile
9
+
2
10
  rvm:
3
11
  - 1.9.3
4
- - 1.9.2
12
+ - 2.0.0
13
+ - 2.1.0
14
+ - 2.2.0
15
+ - rbx-2.4.1
5
16
  - jruby-19mode
17
+ - jruby-head
18
+
6
19
  matrix:
7
20
  allow_failures:
8
21
  - rvm: jruby-19mode
22
+ - rvm: jruby-head
@@ -0,0 +1,14 @@
1
+ appraise "rails32" do
2
+ gem "rails", "~> 3.2"
3
+ gem "sass-rails"
4
+ end
5
+
6
+ appraise "rails41" do
7
+ gem "rails", "~> 4.1.0"
8
+ gem "sass-rails"
9
+ end
10
+
11
+ appraise "rails42" do
12
+ gem "rails", "~> 4.2.0"
13
+ gem "sass-rails", "~> 5.0"
14
+ end
data/Gemfile CHANGED
@@ -1,16 +1,7 @@
1
1
  source 'https://rubygems.org'
2
- gemspec
3
-
4
- platforms :jruby do
5
- gem "jruby-openssl"
6
- end
7
2
 
8
- group :development, :test do
9
- platforms :mri do
10
- gem "debugger"
11
- end
3
+ gemspec
12
4
 
13
- platforms :jruby do
14
- gem "ruby-debug"
15
- end
16
- end
5
+ gem 'appraisal'
6
+ gem 'jruby-openssl', platforms: :jruby
7
+ gem 'pry'
data/README.md CHANGED
@@ -7,15 +7,24 @@ be fetched from a remote API instead of the database.
7
7
 
8
8
  ## Configuration
9
9
 
10
- Apps are where Remotely goes to find association resources. You can define as many as you want, but if you define only one, you can omit the `:app` option from your associations.
10
+ Apps are where Remotely goes to find association resources. You can define as many as you want, but if you define only one, you can omit the `:app` option from your associations. Remotely also supports any Faraday middleware, to configure just call `use_middleware` with the class name and options.
11
11
 
12
12
  Remotely.configure do
13
13
  app :legsapp do
14
14
  url "http://somanylegs.com/api/v1"
15
15
  basic_auth "username", "password"
16
+ use_middleware Faraday::HttpCache, store: MyCache.new
16
17
  end
17
18
  end
18
19
 
20
+ class Millepied < Remotely::Model
21
+ app :legsapp
22
+ uri "/legs"
23
+
24
+ # Optional - restrict saveable attributes
25
+ attr_savable :name, :type
26
+ end
27
+
19
28
  ## Defining Associations
20
29
 
21
30
  `has_many_remote` takes two options, `:app` and `:path`. `:app` tells Remotely which registered app to fetch it from. `:path` tells it the URI to the object (everything after the app).
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "jruby-openssl", :platforms => :jruby
7
+ gem "pry"
8
+ gem "rails", "~> 3.2"
9
+ gem "sass-rails"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "jruby-openssl", :platforms => :jruby
7
+ gem "pry"
8
+ gem "rails", "~> 4.1.0"
9
+ gem "sass-rails"
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "jruby-openssl", :platforms => :jruby
7
+ gem "pry"
8
+ gem "rails", "~> 4.2.0"
9
+ gem "sass-rails", "~> 5.0"
10
+
11
+ gemspec :path => "../"
@@ -48,12 +48,21 @@ module Remotely
48
48
  @authorization = [type, token]
49
49
  end
50
50
 
51
+ def use_middleware(klass, options = {})
52
+ middleware << [klass, options]
53
+ end
54
+
55
+ def middleware
56
+ @middleware ||= []
57
+ end
58
+
51
59
  # Connection to the application (with BasicAuth if it was set).
52
60
  #
53
61
  def connection
54
62
  return unless @url
55
63
 
56
64
  @connection ||= Faraday::Connection.new(@url) do |b|
65
+ middleware.each { |m, opts| b.use(m, opts) }
57
66
  b.request :url_encoded
58
67
  b.adapter :net_http
59
68
  end
@@ -1,6 +1,5 @@
1
1
  module Remotely
2
2
  class Model
3
- extend Forwardable
4
3
  extend ActiveModel::Naming
5
4
  include ActiveModel::Conversion
6
5
  include Associations
@@ -148,7 +147,7 @@ module Remotely
148
147
  end
149
148
  end
150
149
 
151
- def_delegators :"self.class", :uri, :get, :post, :put, :parse_response
150
+ delegate :uri, :get, :post, :put, :parse_response, to: :"self.class"
152
151
 
153
152
  # @return [Hash] Key-value of attributes and values.
154
153
  attr_accessor :attributes
@@ -205,7 +204,7 @@ module Remotely
205
204
  def save
206
205
  method = new_record? ? :post : :put
207
206
  status = new_record? ? 201 : 200
208
- attrs = new_record? ? attributes : attributes.slice(*savable_attributes)
207
+ attrs = new_record? ? attributes : attributes.slice(*savable_attributes << :id)
209
208
  url = new_record? ? uri : URL(uri, id)
210
209
 
211
210
  resp = public_send(method, url, attrs)
@@ -221,7 +220,7 @@ module Remotely
221
220
  end
222
221
 
223
222
  def savable_attributes
224
- (self.class.savable_attributes || attributes.keys) << :id
223
+ self.class.savable_attributes || attributes.keys
225
224
  end
226
225
 
227
226
  # Sets multiple errors with a hash
@@ -296,7 +295,7 @@ module Remotely
296
295
  end
297
296
 
298
297
  def method_missing(name, *args, &block)
299
- if self.attributes.include?(name)
298
+ if self.attributes.include?(name) || self.savable_attributes.include?(name)
300
299
  self.attributes[name]
301
300
  elsif name =~ /(.*)=$/ && self.attributes.include?($1.to_sym)
302
301
  self.attributes[$1.to_sym] = args.first
@@ -1,3 +1,3 @@
1
1
  module Remotely
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_development_dependency "rake"
19
19
  gem.add_development_dependency "rspec", "~> 2.6.0"
20
- gem.add_development_dependency "webmock"
20
+ gem.add_development_dependency "webmock", '~> 1.18.0'
21
21
 
22
22
  gem.add_dependency "activesupport"
23
23
  gem.add_dependency "activemodel"
@@ -59,4 +59,13 @@ describe Remotely::Application do
59
59
  end
60
60
  app.connection.headers["authorization"].should_not be_nil
61
61
  end
62
+
63
+ it "has a list of middleware for faraday to use" do
64
+ CustomMiddleware = Module.new
65
+ app = Remotely::Application.new(:name) do
66
+ url "http://example.com"
67
+ use_middleware CustomMiddleware, { a: 'a', b: 'b'}
68
+ end
69
+ app.connection.builder.handlers.should include(CustomMiddleware)
70
+ end
62
71
  end
@@ -12,6 +12,10 @@ describe Remotely::Model do
12
12
 
13
13
  subject { Adventure.new(attrs) }
14
14
 
15
+ it 'should respond to uninitialized attributes defined as saveable' do
16
+ Adventure.new.name.should == nil
17
+ end
18
+
15
19
  it "stores which attributes are savable" do
16
20
  Adventure.savable_attributes.should == [:name, :type]
17
21
  end
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matte Noble
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-03 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,81 +41,71 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: webmock
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ~>
52
46
  - !ruby/object:Gem::Version
53
- version: '0'
47
+ version: 1.18.0
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ~>
60
53
  - !ruby/object:Gem::Version
61
- version: '0'
54
+ version: 1.18.0
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: activesupport
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: activemodel
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: faraday
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: multi_json
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  description: Remote API based model associations.
@@ -134,9 +119,13 @@ files:
134
119
  - .gitignore
135
120
  - .rspec
136
121
  - .travis.yml
122
+ - Appraisals
137
123
  - Gemfile
138
124
  - README.md
139
125
  - Rakefile
126
+ - gemfiles/rails32.gemfile
127
+ - gemfiles/rails41.gemfile
128
+ - gemfiles/rails42.gemfile
140
129
  - lib/remotely.rb
141
130
  - lib/remotely/application.rb
142
131
  - lib/remotely/associations.rb
@@ -158,27 +147,26 @@ files:
158
147
  - spec/support/webmock.rb
159
148
  homepage: ''
160
149
  licenses: []
150
+ metadata: {}
161
151
  post_install_message:
162
152
  rdoc_options: []
163
153
  require_paths:
164
154
  - lib
165
155
  required_ruby_version: !ruby/object:Gem::Requirement
166
- none: false
167
156
  requirements:
168
- - - ! '>='
157
+ - - '>='
169
158
  - !ruby/object:Gem::Version
170
159
  version: '0'
171
160
  required_rubygems_version: !ruby/object:Gem::Requirement
172
- none: false
173
161
  requirements:
174
- - - ! '>='
162
+ - - '>='
175
163
  - !ruby/object:Gem::Version
176
164
  version: '0'
177
165
  requirements: []
178
166
  rubyforge_project:
179
- rubygems_version: 1.8.23
167
+ rubygems_version: 2.4.1
180
168
  signing_key:
181
- specification_version: 3
169
+ specification_version: 4
182
170
  summary: Remote API based model associations.
183
171
  test_files:
184
172
  - spec/remotely/application_spec.rb