distant 0.1.1 → 0.1.2

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: 730b8a2b639f0f0cac7f5174658e69f64eafb634
4
- data.tar.gz: 39258025d76ebfab214f398130f36872f2fa8971
3
+ metadata.gz: 26713c61cff1da17cdee7e0eb0b26cfa735aa2ec
4
+ data.tar.gz: 699ec5c4908a19d80dba0f9c84226ce02e2208e8
5
5
  SHA512:
6
- metadata.gz: c66735d6409692b5c80e6c74a00a07048b18bf6f76ff9e54990b8cfc67ed016d11122e34622741c9864a4e72521d558e792be1c77ee3208f9b43d962cf78dc52
7
- data.tar.gz: f61b848ee6324101a6514aeebfbf1eaca88e45127d3798de1e8b67f87d9735234275c782473b38244d2b3f07dc5fa43f5d95ba9e2528386e6d01e7e9db6709be
6
+ metadata.gz: 278282dcb599fc56884c04b9b10782f65615813fd5dee3726d2a277b589cffc887e499718f9b5ad74cf7c8c0225a682c6ecbf8cd418de6be614a7e72f0afed73
7
+ data.tar.gz: df11c199e6bf8de859cbb3fe585c949e390aa486cc8c13d90ed9efb1a84df385265142473ae4a164df1ba9cbf4796be198b263b0439dd88355cd6bf8763624d0
data/distant.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'distant'
3
- spec.version = '0.1.1'
3
+ spec.version = '0.1.2'
4
4
  spec.authors = ['John Drago']
5
5
  spec.email = 'jdrago.999@gmail.com'
6
6
  spec.homepage = 'https://github.com/distant/distant'
data/lib/distant/base.rb CHANGED
@@ -11,6 +11,7 @@ module Distant
11
11
 
12
12
  def self.inherited(klass)
13
13
  klass.extend(ClassMethods)
14
+ klass.init_class_vars
14
15
  end
15
16
 
16
17
  def connection
@@ -18,6 +19,11 @@ module Distant
18
19
  end
19
20
 
20
21
  module ClassMethods
22
+ def init_class_vars
23
+ @has_many = [ ]
24
+ @belongs_to = [ ]
25
+ end
26
+
21
27
  def connection
22
28
  @@connection ||= Distant::Connection.new( Distant.config )
23
29
  end
@@ -41,6 +47,7 @@ module Distant
41
47
  end
42
48
 
43
49
  def has_many(plural, route)
50
+ @has_many << plural.to_sym
44
51
  define_method(plural) do
45
52
  path = self.class.path_closure_generator(route).call(id: self.id)
46
53
  headers = Distant.config.default_headers('')
@@ -51,7 +58,16 @@ module Distant
51
58
  end
52
59
  end
53
60
 
61
+ def has_many?(plural)
62
+ @has_many.include? plural.to_sym
63
+ end
64
+
65
+ def belongs_to?(singular)
66
+ @belongs_to.include? singular.to_sym
67
+ end
68
+
54
69
  def belongs_to(singular, route)
70
+ @belongs_to << singular.to_sym
55
71
  define_method(singular) do
56
72
  foreign_key_attr = singular.to_s + '_id'
57
73
  foreign_key_value = self.send(foreign_key_attr)
@@ -223,4 +223,34 @@ describe Distant::Base do
223
223
  end
224
224
  end
225
225
  end
226
+
227
+ describe '#has_many?(other_things)' do
228
+ context 'when the thing' do
229
+ context 'does have many other_things' do
230
+ it 'returns true' do
231
+ expect(Distant::BaseTest.has_many?(:sub_tests)).to be_truthy
232
+ end
233
+ end
234
+ context 'does not have many other_things' do
235
+ it 'returns false' do
236
+ expect(Distant::BaseTest.has_many?(:sdf987sd98f7)).to be_falsey
237
+ end
238
+ end
239
+ end
240
+ end
241
+
242
+ describe '#belongs_to?(other_thing)' do
243
+ context 'when the thing' do
244
+ context 'does belong to other_thing' do
245
+ it 'returns true' do
246
+ expect(Distant::SubTest.belongs_to?(:base_test)).to be_truthy
247
+ end
248
+ end
249
+ context 'does not have many other_things' do
250
+ it 'returns false' do
251
+ expect(Distant::SubTest.belongs_to?(:kjh234kjh23kj4h)).to be_falsey
252
+ end
253
+ end
254
+ end
255
+ end
226
256
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: distant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Drago