datamapa 1.0.1 → 1.1.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: 75b5c6f148def5270cd9d0c419aea373c6adcdf7
4
- data.tar.gz: 375e0436814188812af10fc872d71940b07a76c6
3
+ metadata.gz: 8e917084badaf650175757ecdd386e8aeab8fb2f
4
+ data.tar.gz: 18ad105bd4dac4a470cfb40ea4f1e4d4fb9118d3
5
5
  SHA512:
6
- metadata.gz: e62617c40aa2526d284ed4669ff36cda673c330b0022a1acaee43646a700fe4443b407e514e1f9dc7cd456cdfd8bbfb90935c2d69fddcaec3431be04f723f961
7
- data.tar.gz: 9756baa220e9dca6051f468dd6785377ec4e29c26747bff06617be8421060c5e4dbed6246066075653ce659b62c008066219331219696abd9470aef6ca5cf0d5
6
+ metadata.gz: e44fc689ecd1e0850381efb77d604976b5f780b5d1dab641e79139536f69b693a241643aa21df2f19b54d7462b75d41e2500e3de912f4b05b99b30d2e582435f
7
+ data.tar.gz: c4ed826adc1a9ee45b318dec04270b17fff740b444dad88a7bdf2a998428626e5248194f8cbc1f37a574383fdc9dd344d7dca41dafa493c79dd9f140ebf99344
@@ -1,3 +1,3 @@
1
1
  module DataMapa
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/datamapa.rb CHANGED
@@ -53,6 +53,15 @@ module DataMapa
53
53
  end
54
54
  end
55
55
 
56
+ def exists?(model)
57
+ if model.id.nil?
58
+ load_id_with_semantic_key(model) unless @semantic_key.nil?
59
+ !model.id.nil?
60
+ else
61
+ @ar_class.exists?(model.id)
62
+ end
63
+ end
64
+
56
65
  def where(clause)
57
66
  records = @ar_class.where(clause)
58
67
  records.map do |ar|
@@ -322,6 +322,27 @@ describe DataMapa do
322
322
  model.id.must_equal id
323
323
  end
324
324
 
325
+ it "checks existence with technical key" do
326
+ model = model_class.new
327
+ model.id = 1
328
+
329
+ ar_class.stubs(:exists?).with(model.id).returns(true)
330
+
331
+ mapper.exists?(model).must_equal true
332
+ end
333
+
334
+ it "checks existence with semantic key" do
335
+ model = model_class.new
336
+ model.key1 = 10
337
+ model.key2 = 20
338
+
339
+ tech_key = 100
340
+
341
+ ar_class.stubs(:find_by).with(key1: 10, key2: 20).returns(ar_class.new(tech_key))
342
+
343
+ mapper.exists?(model).must_equal true
344
+ model.id.must_equal tech_key
345
+ end
325
346
  end
326
347
 
327
348
  describe "composition" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datamapa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yosuke Doi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-23 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord