rrepo 0.2.5 → 0.2.6

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: 5a449aa17c6282e6c132c4d7d79c0400555be53e
4
- data.tar.gz: daa276248dde47975a585a5fd8214e56b714c2e5
3
+ metadata.gz: 7f7d90ccdf68a5f7982f1f0e456481185c328f97
4
+ data.tar.gz: 074a1fb8b2112f4df91efe51d2d0caa99ebe5b81
5
5
  SHA512:
6
- metadata.gz: 26ea9b47b42fd86c4b9c904df9cece0192d6115e419ff76ee103513c36b63912b0fbe1ee6e7ed411e9553359f9e57774ad42b2177763cbb8da11b622303dba8a
7
- data.tar.gz: 951ca5cb050c813d8e31e3765a9c5794ba5335dc9da2bfc3765871a207884bf6d4f83dcabb20ed33f9b76bba177d364ea59e70f03041ecffa943c24a1e005846
6
+ metadata.gz: 8421ce9ef55652c69e4aa3352c4960a2af5a6ffe0d595381a5c79f2446b8d3001da72428bd823e22aa47004340b2adc5348c74375edccdbcd2ac9d0056118de9
7
+ data.tar.gz: 9b561e91101fdd12c9bce674c955112e02cd862c67f00cb5802601bfa6737ebea5db68a2670ac3ecf1c15afcec005501b2b17f94ee56c393cda085e2b40e5151
@@ -14,22 +14,19 @@ module RRepo
14
14
  @collection
15
15
  end
16
16
 
17
- def model_class_name(name = nil)
17
+ def model_class_name(name = nil, &block)
18
18
  return @model_class_name = name if name.present?
19
+ return @model_class_name = block if block_given?
19
20
  @model_class_name
20
21
  end
21
22
  end
22
23
 
23
- attr_reader :collection, :adapter, :model_class
24
+ attr_reader :collection, :adapter
24
25
 
25
26
  def initialize(adapter)
26
27
  @adapter = adapter
27
28
  class_name = self.class.name.demodulize
28
29
  @collection = (self.class.collection || class_name.underscore).to_sym
29
- return if class_name == 'Repository'
30
- @model_class = (
31
- self.class.model_class_name || class_name.singularize
32
- ).constantize
33
30
  end
34
31
 
35
32
  def create(model)
@@ -55,12 +52,12 @@ module RRepo
55
52
 
56
53
  def all
57
54
  result = adapter.all(collection)
58
- result.map(&model_class.method(:new))
55
+ result.map(&method(:model_for))
59
56
  end
60
57
 
61
58
  def find(id)
62
59
  result = adapter.find(collection, id)
63
- model_class.new(result)
60
+ model_for(result)
64
61
  end
65
62
 
66
63
  def clear
@@ -70,5 +67,20 @@ module RRepo
70
67
  def query(&block)
71
68
  adapter.query(collection, &block)
72
69
  end
70
+
71
+ def model_class(attributes = {})
72
+ if self.class.model_class_name.respond_to?(:call)
73
+ model_class_name = self.class.model_class_name.call(attributes)
74
+ else
75
+ model_class_name = (
76
+ self.class.model_class_name || self.class.name.demodulize.singularize
77
+ )
78
+ end
79
+ model_class_name.constantize
80
+ end
81
+
82
+ def model_for(attributes)
83
+ model_class(attributes).new(attributes)
84
+ end
73
85
  end
74
86
  end
data/lib/rrepo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RRepo
2
- VERSION = '0.2.5'.freeze
2
+ VERSION = '0.2.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rrepo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Reinert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-23 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler