Module: IseshimaStore::Base::ClassMethods
- Defined in:
- lib/iseshima_store/base.rb
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
- #attr_properties(*args) ⇒ Object
- #destroy_all ⇒ Object
- #from_entity(entity) ⇒ Object
- #scoping ⇒ Object
- #search(options = {}) ⇒ Object
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
30 31 32 |
# File 'lib/iseshima_store/base.rb', line 30 def properties @properties end |
Instance Method Details
#attr_properties(*args) ⇒ Object
40 41 42 43 |
# File 'lib/iseshima_store/base.rb', line 40 def attr_properties(*args) attr_accessor(*args) @properties = args end |
#destroy_all ⇒ Object
32 33 34 |
# File 'lib/iseshima_store/base.rb', line 32 def destroy_all scoping.each(&:destroy) end |
#from_entity(entity) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/iseshima_store/base.rb', line 45 def from_entity(entity) instance = self.new instance.id = entity.key.id entity.properties.to_hash.each do |name, value| if instance.respond_to?("#{name}=") instance.send "#{name}=", value end end instance.parent_key = entity.key.parent instance end |
#scoping ⇒ Object
36 37 38 |
# File 'lib/iseshima_store/base.rb', line 36 def scoping IseshimaStore::Relation.new(self) end |
#search(options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/iseshima_store/base.rb', line 57 def search( = {}) query = if [:query] [:query] else query = Gcloud::Datastore::Query.new query.kind(self.to_s) query.limit([:limit]) if [:limit] query.cursor([:cursor]) if [:cursor] query end results = IseshimaStore::Connection.current.run(query) records = results.map { |entity| from_entity(entity) } if [:limit] && results.size == [:limit] next_cursor = results.cursor end { records: records, cursor: next_cursor } end |