Module: Ultrafast::Model

Defined in:
lib/ultrafast/model.rb

Instance Method Summary collapse

Instance Method Details

#current_application_nameObject



27
28
29
# File 'lib/ultrafast/model.rb', line 27

def current_application_name
  Ultrafast::CurrentApplication.name
end

#error_messageObject



31
32
33
34
35
# File 'lib/ultrafast/model.rb', line 31

def error_message
  Rails.logger.warn '-----------------------------------------------------'
  Rails.logger.warn '[WARN Error] on try use fastcreate, running fallback'
  Rails.logger.warn '-----------------------------------------------------'
end

#fast_create(*attributes) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/ultrafast/model.rb', line 3

def fast_create(*attributes)
  uuid = SecureRandom.uuid
  store_key = "#{self.current_application_name}.#{self.name}.create.#{Time.now.to_i}.#{uuid}"
  content = attributes.to_json

  redis_connection.set(store_key, content)
  self.new(attributes)
rescue
  error_message
  self.create(*attributes)
end

#fast_default_amountObject



19
20
21
# File 'lib/ultrafast/model.rb', line 19

def fast_default_amount
  100
end

#has_fast_createObject



15
16
17
# File 'lib/ultrafast/model.rb', line 15

def has_fast_create
  true
end

#redis_connectionObject



23
24
25
# File 'lib/ultrafast/model.rb', line 23

def redis_connection
  Ultrafast::Storage.redis_connection
end