Module: Schron::Archive
- Includes:
- Interface
- Included in:
- GenericArchive, Repository
- Defined in:
- lib/schron/archive.rb,
lib/schron/archive/interface.rb
Defined Under Namespace
Modules: Interface
Instance Attribute Summary collapse
-
#datastore ⇒ Object
readonly
Returns the value of attribute datastore.
-
#entity_class ⇒ Object
readonly
Returns the value of attribute entity_class.
-
#indexed_fields ⇒ Object
readonly
Returns the value of attribute indexed_fields.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #dump(object) ⇒ Object
- #dump_all(objects) ⇒ Object
- #first ⇒ Object
- #get(id) ⇒ Object
- #initialize(datastore, kind: nil, entity_class: nil, indexed_fields: nil) {|_self| ... } ⇒ Object
- #insert(object) ⇒ Object
- #load(attributes) ⇒ Object
- #load_all(attributes) ⇒ Object
- #multi_get(ids) ⇒ Object
- #multi_insert(objects) ⇒ Object
- #query(&block) ⇒ Object
Methods included from Interface
Instance Attribute Details
#datastore ⇒ Object (readonly)
Returns the value of attribute datastore.
14 15 16 |
# File 'lib/schron/archive.rb', line 14 def datastore @datastore end |
#entity_class ⇒ Object (readonly)
Returns the value of attribute entity_class.
14 15 16 |
# File 'lib/schron/archive.rb', line 14 def entity_class @entity_class end |
#indexed_fields ⇒ Object (readonly)
Returns the value of attribute indexed_fields.
14 15 16 |
# File 'lib/schron/archive.rb', line 14 def indexed_fields @indexed_fields end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
14 15 16 |
# File 'lib/schron/archive.rb', line 14 def kind @kind end |
Class Method Details
.included(archive_class) ⇒ Object
8 9 10 |
# File 'lib/schron/archive.rb', line 8 def self.included(archive_class) archive_class.extend Schron::DSL end |
Instance Method Details
#all ⇒ Object
31 32 33 |
# File 'lib/schron/archive.rb', line 31 def all query.all end |
#dump(object) ⇒ Object
55 56 57 58 59 |
# File 'lib/schron/archive.rb', line 55 def dump(object) object.attributes.each_with_object({}) do |(k,v), h| h[dump_value(k)] = dump_value(v) end end |
#dump_all(objects) ⇒ Object
67 68 69 |
# File 'lib/schron/archive.rb', line 67 def dump_all(objects) objects.map { |o| dump(o) } end |
#first ⇒ Object
35 36 37 |
# File 'lib/schron/archive.rb', line 35 def first query.first end |
#get(id) ⇒ Object
39 40 41 |
# File 'lib/schron/archive.rb', line 39 def get(id) maybe_load(@datastore.get(@kind, id)) end |
#initialize(datastore, kind: nil, entity_class: nil, indexed_fields: nil) {|_self| ... } ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/schron/archive.rb', line 16 def initialize(datastore, kind: nil, entity_class: nil, indexed_fields: nil) @datastore = datastore @kind = kind || self.class.kind @entity_class = entity_class || self.class.entity_class @indexed_fields = indexed_fields || self.class.indexed_fields yield self if block_given? end |
#insert(object) ⇒ Object
47 48 49 |
# File 'lib/schron/archive.rb', line 47 def insert(object) maybe_load(@datastore.insert(@kind, dump(object))) end |
#load(attributes) ⇒ Object
61 62 63 64 65 |
# File 'lib/schron/archive.rb', line 61 def load(attributes) attributes.nil? ? nil : entity_class.new(attributes) end |
#load_all(attributes) ⇒ Object
71 72 73 |
# File 'lib/schron/archive.rb', line 71 def load_all(attributes) attributes.map { |attrs| maybe_load(attrs) } end |
#multi_get(ids) ⇒ Object
43 44 45 |
# File 'lib/schron/archive.rb', line 43 def multi_get(ids) load_all(@datastore.multi_get(@kind, ids)).compact end |
#multi_insert(objects) ⇒ Object
51 52 53 |
# File 'lib/schron/archive.rb', line 51 def multi_insert(objects) load_all(@datastore.multi_insert(@kind, dump_all(objects))) end |
#query(&block) ⇒ Object
27 28 29 |
# File 'lib/schron/archive.rb', line 27 def query(&block) Query.new(self, &block) end |