active_pstore 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efadacd9f6d04884f4b26326c49b44ff0f36cc25
4
- data.tar.gz: 2ba9d7297cbcafe5709ad89aa645b8443a0dd13b
3
+ metadata.gz: 3ebab73c6f6546e1154c1378f6033395789ea405
4
+ data.tar.gz: a57ed34a2b0ea37fae184081a0da68d7835fc2d1
5
5
  SHA512:
6
- metadata.gz: e3efcd40631c1e9dab7d29ad022eb73e6de8cf2dd61fa4cf47299087a189d46cfa508d44e63d07d60c56a0757237392ef2a162376cb059718c5202e443c5218a
7
- data.tar.gz: 2309b2c90e7a9ee20575c90bb2f99656807527c3924a4b30dfc2869a5b07f7a63d9294dba8dd3aa9e08917cfb20b7675bab419e9d6895c6d239253139219a2c8
6
+ metadata.gz: 726de17ef5ea0b416c0da6c39801e1a954de39b523e9dd3d7ad5dba2f85e07c47fa7d409897f12ccfd23862fd73b138ecc7003451b5a46bdc485652d605de504
7
+ data.tar.gz: ddb7aca9f701696d90942b74f5e377345cbfda23a1f21b15c5394f8530a2d6732d2d56de028cccea3a0847d769efd4cbce11f1dcc4b59d5e19764585561b9f36
data/README.ja.md CHANGED
@@ -43,6 +43,12 @@ randy_rhoads.save
43
43
 
44
44
  saveメソッドの対象オブジェクトのクラス名がPStoreのキーになります。
45
45
 
46
+ ```ruby
47
+ Artist.table_name # => 'Artist'
48
+ ```
49
+
50
+ 例えばPStoreをもちいて保存されたartistオブジェクトを取得してみます。
51
+
46
52
  ```ruby
47
53
  database = PStore.new('/path/to/file')
48
54
  database.transaction {|db| artist = db['Artist'] } # fetch instances of Artist class.
data/README.md CHANGED
@@ -42,6 +42,12 @@ randy_rhoads.save
42
42
 
43
43
  database key is string of class name.
44
44
 
45
+ ```ruby
46
+ Artist.table_name # => 'Artist'
47
+ ```
48
+
49
+ ex) Fetch stored artist objects by pure PStore.
50
+
45
51
  ```ruby
46
52
  database = PStore.new('/path/to/file')
47
53
  database.transaction {|db| artist = db['Artist'] } # fetch instances of Artist class.
@@ -50,9 +56,9 @@ database.transaction {|db| artist = db['Artist'] } # fetch instances of Artist c
50
56
  allocate value of ActivePStore::Base#id using [SecureRandom.hex](http://ruby-doc.org/stdlib-2.2.0/libdoc/securerandom//rdoc/SecureRandom.html#method-c-hex).
51
57
 
52
58
  ```ruby
53
- > foo.id # => nil
59
+ > randy_rhoads.id # => nil
54
60
  > randy_rhoads.save
55
- > foo.id # => "0b84ece5d5be3bce3ee2101c1c4f6fda"
61
+ > randy_rhoads.id # => "0b84ece5d5be3bce3ee2101c1c4f6fda"
56
62
  ```
57
63
 
58
64
  ### find series
data/lib/active_pstore.rb CHANGED
@@ -7,6 +7,7 @@ require 'active_pstore/core'
7
7
  require 'active_pstore/dynamic_matchers'
8
8
  require 'active_pstore/finder_methods'
9
9
  require 'active_pstore/inheritance'
10
+ require 'active_pstore/model_schema'
10
11
  require 'active_pstore/persistence'
11
12
  require 'active_pstore/query_methods'
12
13
  require 'active_pstore/querying'
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  module ActivePStore
2
4
  class Base
3
5
  extend ActivePStore::ConnectionHandling
@@ -6,31 +8,20 @@ module ActivePStore
6
8
  extend ActivePStore::Inheritance
7
9
  extend ActivePStore::Querying
8
10
  extend ActivePStore::QueryMethods
11
+ extend ActivePStore::ModelSchema
9
12
  include ActivePStore::Core
10
13
  include ActivePStore::Persistence
11
14
 
15
+ extend SingleForwardable
16
+
17
+ def_delegators :all, :ids, :count, :minimum, :maximum
18
+
12
19
  class << self
13
20
  def all
14
21
  use_connection do |connection|
15
22
  ActivePStore::Collection.new(connection[self.pstore_key] || [])
16
23
  end
17
24
  end
18
-
19
- def ids
20
- all.ids
21
- end
22
-
23
- def minimum(attr_name)
24
- all.minimum(attr_name)
25
- end
26
-
27
- def maximum(attr_name)
28
- all.maximum(attr_name)
29
- end
30
-
31
- def pstore_key
32
- self.to_s
33
- end
34
25
  end
35
26
  end
36
27
  end
@@ -20,8 +20,12 @@ module ActivePStore
20
20
  }
21
21
  end
22
22
 
23
- def count
24
- @objects.count
23
+ def count(attr_name = nil)
24
+ if attr_name.nil? || attr_name == :all
25
+ @objects.count
26
+ else
27
+ @objects.map(&attr_name.to_sym).compact.count
28
+ end
25
29
  end
26
30
 
27
31
  def empty?
@@ -0,0 +1,9 @@
1
+ module ActivePStore
2
+ module ModelSchema
3
+ def pstore_key
4
+ self.to_s
5
+ end
6
+
7
+ alias table_name pstore_key
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module ActivePStore
2
- VERSION = '0.4.5'
2
+ VERSION = '0.4.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_pstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi ITO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-09 00:00:00.000000000 Z
11
+ date: 2015-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter
@@ -57,6 +57,7 @@ files:
57
57
  - lib/active_pstore/errors.rb
58
58
  - lib/active_pstore/finder_methods.rb
59
59
  - lib/active_pstore/inheritance.rb
60
+ - lib/active_pstore/model_schema.rb
60
61
  - lib/active_pstore/persistence.rb
61
62
  - lib/active_pstore/query_methods.rb
62
63
  - lib/active_pstore/querying.rb