Class: CrontabRb::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/crontab_rb/database.rb

Constant Summary collapse

CRONTABRB =
'crontab_rb'
@@pstore =
PStore.new("#{CrontabRb.configuration.path_storage}#{CRONTABRB}.pstore")

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Database

Returns a new instance of Database.



11
12
13
14
15
16
17
18
19
# File 'lib/crontab_rb/database.rb', line 11

def initialize(options={})
  @options                 = {}
  @options[:id]            = options[:id] || SecureRandom.uuid
  @options[:name]          = options[:name]
  @options[:command]       = options[:command]
  @options[:time]          = options[:time]
  @options[:at]            = options[:at]
  @options[:updated_at]    = Time.now.strftime("%Y-%m-%d %H:%M:%S")
end

Class Method Details

.allObject



25
26
27
28
29
# File 'lib/crontab_rb/database.rb', line 25

def self.all
  @@pstore.transaction(true) do
    @@pstore.roots.map {|root| @@pstore[root]}
  end
end

.create(options = {}) ⇒ Object



21
22
23
# File 'lib/crontab_rb/database.rb', line 21

def self.create(options={})
  new(options).save
end

.delete(name) ⇒ Object



37
38
39
40
41
# File 'lib/crontab_rb/database.rb', line 37

def self.delete(name)
  @@pstore.transaction do
    @@pstore.delete(name)
  end
end

.find(name) ⇒ Object



31
32
33
34
35
# File 'lib/crontab_rb/database.rb', line 31

def self.find(name)
  @@pstore.transaction(true) do
    @@pstore[name]
  end
end

Instance Method Details

#saveObject



43
44
45
46
47
48
# File 'lib/crontab_rb/database.rb', line 43

def save
  @@pstore.transaction do
    @@pstore[@options[:id]] = @options
    @options
  end
end