Class: AlPersist
- Inherits:
-
Object
- Object
- AlPersist
- Defined in:
- lib/al_persist.rb
Overview
データ永続化 ベースクラス
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (AlRdbw) persist_base
readonly
使用する RDB wrapper オブジェクト.
-
- (Array<Symbol>) pkeys
readonly
プライマリキーの配列.
-
- (Hash) search_condition
readonly
検索条件のキャッシュ.
-
- (Hash) values
管理するアトリビュート.
Instance Method Summary (collapse)
-
- (String) [](k)
attribute getter.
-
- (Object) []=(k, v)
attribute setter.
-
- (Integer, Nil) get_next_offset
検索時、次ページのオフセット値を得る.
-
- (Integer, Nil) get_previous_offset
検索時、前ページのオフセット値を得る.
-
- (AlPersist) initialize(base, keys = nil)
constructor
constructor.
-
- (self) pkey(*keys)
primary key setter.
Constructor Details
- (AlPersist) initialize(base, keys = nil)
constructor
36 37 38 39 40 41 |
# File 'lib/al_persist.rb', line 36 def initialize( base, keys = nil ) @persist_base = base @values = {} pkey( keys ) @search_condition = {} end |
Instance Attribute Details
- (AlRdbw) persist_base (readonly)
使用する RDB wrapper オブジェクト
18 19 20 |
# File 'lib/al_persist.rb', line 18 def persist_base @persist_base end |
- (Array<Symbol>) pkeys (readonly)
プライマリキーの配列
24 25 26 |
# File 'lib/al_persist.rb', line 24 def pkeys @pkeys end |
- (Hash) search_condition (readonly)
検索条件のキャッシュ
27 28 29 |
# File 'lib/al_persist.rb', line 27 def search_condition @search_condition end |
- (Hash) values
管理するアトリビュート
21 22 23 |
# File 'lib/al_persist.rb', line 21 def values @values end |
Instance Method Details
- (String) [](k)
attribute getter
76 77 78 |
# File 'lib/al_persist.rb', line 76 def []( k ) return @values[k.to_sym] end |
- (Object) []=(k, v)
attribute setter
87 88 89 |
# File 'lib/al_persist.rb', line 87 def []=( k, v ) @values[k.to_sym] = v end |
- (Integer, Nil) get_next_offset
検索時、次ページのオフセット値を得る
97 98 99 100 101 102 103 104 |
# File 'lib/al_persist.rb', line 97 def get_next_offset() total_rows = @search_condition[:total_rows].to_i num_rows = @search_condition[:num_rows].to_i limit = @search_condition[:limit].to_i offset = @search_condition[:offset].to_i return (offset + num_rows) < total_rows ? (offset + limit) : nil end |
- (Integer, Nil) get_previous_offset
検索時、前ページのオフセット値を得る
112 113 114 115 116 117 |
# File 'lib/al_persist.rb', line 112 def get_previous_offset() limit = @search_condition[:limit].to_i offset = @search_condition[:offset].to_i return offset > 0 ? (offset - limit) : nil end |
- (self) pkey(*keys)
primary key setter
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/al_persist.rb', line 50 def pkey( *keys ) @pkeys = [] keys.flatten.each do |k| case k when String @pkeys << k.to_sym when Symbol @pkeys << k when NilClass # nothing else raise 'Needs key by String or Symbol' end end return self end |