Class: DataMapper::Adapters::ParseAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- DataMapper::Adapters::ParseAdapter
- Includes:
- Parse::Conditions, Query::Conditions
- Defined in:
- lib/adapters/parse_adapter.rb
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
Instance Method Summary collapse
- #create(resources) ⇒ Object
- #delete(resources) ⇒ Object
-
#initialize(name, options) ⇒ ParseAdapter
constructor
A new instance of ParseAdapter.
- #read(query) ⇒ Object
-
#read_count(query) ⇒ Integer
Read the “count” from Parse This is Parse-only.
-
#request_password_reset(email) ⇒ Hash
Request a password reset email Parse-only.
-
#sign_in(username, password) ⇒ Hash
Login, which is Parse-only.
- #update(attributes, resources) ⇒ Object
-
#upload_file(filename, content, content_type) ⇒ Hash
Upload a file Parse-only.
Constructor Details
#initialize(name, options) ⇒ ParseAdapter
Returns a new instance of ParseAdapter.
14 15 16 17 18 |
# File 'lib/adapters/parse_adapter.rb', line 14 def initialize(name, ) super master = @options[:master].nil? ? false : @options[:master] @engine = Parse::Engine.new @options[:app_id], @options[:api_key], master end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
12 13 14 |
# File 'lib/adapters/parse_adapter.rb', line 12 def engine @engine end |
Instance Method Details
#create(resources) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/adapters/parse_adapter.rb', line 20 def create(resources) resources.each do |resource| # use resource.dirty_attributes, # or else new resource with CarrierWave uploader # cannot be created. params = resource.dirty_attributes.inject({}) { |result, (property, value)| result.merge!(property.field => value) }.except("objectId", "createdAt", "updatedAt") model = resource.model storage_name = model.storage_name result = engine.create storage_name, params initialize_serial resource, result["objectId"] resource.created_at = resource.updated_at = result["createdAt"] end.size end |
#delete(resources) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/adapters/parse_adapter.rb', line 116 def delete(resources) resources.each do |resource| storage_name = resource.model.storage_name engine.delete storage_name, resource.id end.size end |
#read(query) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/adapters/parse_adapter.rb', line 35 def read(query) model = query.model params = parse_params_for(query) storage_name = model.storage_name response = engine.read storage_name, params response["results"] rescue NotImplementedError log :error, "Unsupported Query:" log :error, " Model: #{model}" log :error, " Conditions: #{query.conditions}" raise NotImplementedError end |
#read_count(query) ⇒ Integer
Read the “count” from Parse This is Parse-only
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/adapters/parse_adapter.rb', line 60 def read_count(query) model = query.model params = parse_params_for(query) params[:count] = 1 params[:limit] = 0 storage_name = model.storage_name response = engine.read storage_name, params response["count"] end |
#request_password_reset(email) ⇒ Hash
Request a password reset email Parse-only
94 95 96 |
# File 'lib/adapters/parse_adapter.rb', line 94 def request_password_reset(email) engine.request_password_reset email end |
#sign_in(username, password) ⇒ Hash
Login, which is Parse-only
82 83 84 |
# File 'lib/adapters/parse_adapter.rb', line 82 def sign_in(username, password) engine.sign_in username, password end |
#update(attributes, resources) ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/adapters/parse_adapter.rb', line 124 def update(attributes, resources) resources.each do |resource| params = attributes_as_fields(attributes).except("createdAt", "updatedAt") storage_name = resource.model.storage_name engine.update storage_name, resource.id, params end.size end |
#upload_file(filename, content, content_type) ⇒ Hash
Upload a file Parse-only
112 113 114 |
# File 'lib/adapters/parse_adapter.rb', line 112 def upload_file(filename, content, content_type) engine.upload_file filename, content, content_type end |