Module: ActAsFireRecordBeta

Extended by:
ActiveSupport::Concern, Forwardable
Includes:
ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Validations, ActiveModel::Validations::Callbacks
Defined in:
lib/act_as_fire_record_beta.rb,
lib/act_as_fire_record_beta/errors.rb,
lib/act_as_fire_record_beta/railtie.rb,
lib/act_as_fire_record_beta/version.rb

Defined Under Namespace

Classes: FireRecordError, OperationNotSupported, Railtie, RecordNotFound, RecordNotSaved

Constant Summary collapse

VERSION =
"0.0.11"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.class_mappingObject



18
19
20
# File 'lib/act_as_fire_record_beta.rb', line 18

def self.class_mapping
  @class_mapping
end

Instance Method Details

#destroyObject



190
191
192
193
# File 'lib/act_as_fire_record_beta.rb', line 190

def destroy
  doc.delete
  true
end

#inspectObject

Override



196
197
198
199
200
# File 'lib/act_as_fire_record_beta.rb', line 196

def inspect
  hash = attributes.transform_keys(&:to_sym)
  hash_text = hash.to_s[1..-2]
  "#<#{self.class} #{hash_text}>"
end

#new_record?Boolean

ClassMethods

Returns:

  • (Boolean)


155
156
157
# File 'lib/act_as_fire_record_beta.rb', line 155

def new_record?
  id.blank?
end

#persisted?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/act_as_fire_record_beta.rb', line 159

def persisted?
  !new_record?
end

#saveObject



163
164
165
166
167
168
169
170
171
# File 'lib/act_as_fire_record_beta.rb', line 163

def save
  raise ActAsFireRecordBeta::OperationNotSupported, "insert only." unless new_record?
  return false if invalid?

  ref = col.add(save_params)
  self.id = ref.document_id

  true
end

#save!Object



173
174
175
# File 'lib/act_as_fire_record_beta.rb', line 173

def save!
  save || raise(ActAsFireRecordBeta::RecordNotSaved, "Failed to save the record")
end

#update(params) ⇒ Object



177
178
179
180
181
182
183
184
# File 'lib/act_as_fire_record_beta.rb', line 177

def update(params)
  raise "update only" if new_record?
  self.attributes = params
  return false if invalid?

  doc.set(save_params, merge: true)
  true
end

#update!(params) ⇒ Object



186
187
188
# File 'lib/act_as_fire_record_beta.rb', line 186

def update!(params)
  update(params) || raise(ActAsFireRecordBeta::RecordNotSaved, "Failed to save the record")
end