Class: CrontabRb::Cron
- Inherits:
-
Object
- Object
- CrontabRb::Cron
- Defined in:
- lib/crontab_rb/cron.rb
Instance Attribute Summary collapse
-
#at ⇒ Object
Returns the value of attribute at.
-
#command ⇒ Object
Returns the value of attribute command.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#time ⇒ Object
Returns the value of attribute time.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Class Method Summary collapse
- .all ⇒ Object
- .convert_to_symbol(hash) ⇒ Object
- .create(options = {}) ⇒ Object
- .destroy(id) ⇒ Object
- .find(id) ⇒ Object
- .update(id, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Cron
constructor
A new instance of Cron.
- #validate ⇒ Object
- #write_crontab ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Cron
10 11 12 13 14 15 16 17 |
# File 'lib/crontab_rb/cron.rb', line 10 def initialize(attributes={}) @id = attributes[:id] @name = attributes[:name] @command = attributes[:command] @time = attributes[:time] @at = attributes[:at] @updated_at = attributes[:updated_at] end |
Instance Attribute Details
#at ⇒ Object
Returns the value of attribute at.
7 8 9 |
# File 'lib/crontab_rb/cron.rb', line 7 def at @at end |
#command ⇒ Object
Returns the value of attribute command.
5 6 7 |
# File 'lib/crontab_rb/cron.rb', line 5 def command @command end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/crontab_rb/cron.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/crontab_rb/cron.rb', line 4 def name @name end |
#time ⇒ Object
Returns the value of attribute time.
6 7 8 |
# File 'lib/crontab_rb/cron.rb', line 6 def time @time end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
8 9 10 |
# File 'lib/crontab_rb/cron.rb', line 8 def updated_at @updated_at end |
Class Method Details
.all ⇒ Object
30 31 32 33 34 35 |
# File 'lib/crontab_rb/cron.rb', line 30 def self.all records = Database.all records.map {|record| new(record)} rescue [] end |
.convert_to_symbol(hash) ⇒ Object
69 70 71 |
# File 'lib/crontab_rb/cron.rb', line 69 def self.convert_to_symbol(hash) Hash[hash.map{|k, v| [k.to_sym, v]}] end |
.create(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/crontab_rb/cron.rb', line 19 def self.create(={}) = convert_to_symbol() cron = new() cron.validate record = Database.create() cron.id = record[:id] cron.updated_at = record[:updated_at] cron.write_crontab cron end |
.destroy(id) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/crontab_rb/cron.rb', line 56 def self.destroy(id) record = Database.find(id) return nil if record.nil? cron = new(record) Database.delete(id) cron.write_crontab cron end |
.find(id) ⇒ Object
37 38 39 40 |
# File 'lib/crontab_rb/cron.rb', line 37 def self.find(id) record = Database.find(id) record.nil? ? nil : new(record) end |
.update(id, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/crontab_rb/cron.rb', line 42 def self.update(id, ={}) record = Database.find(id) return nil if record.nil? record[:name] = [:name] || record[:name] record[:command] = [:command] || record[:command] record[:time] = [:time] || record[:time] record[:at] = [:at] || record[:at] cron = new(record) cron.validate Database.new(record).save cron.write_crontab cron end |
Instance Method Details
#validate ⇒ Object
65 66 67 |
# File 'lib/crontab_rb/cron.rb', line 65 def validate raise "Time attribute of crontab_rb only accept #{CrontabRb::Template::EVERY.keys.join(",")}" unless CrontabRb::Template::EVERY.keys.include?(time) end |
#write_crontab ⇒ Object
73 74 75 |
# File 'lib/crontab_rb/cron.rb', line 73 def write_crontab Write.write_crontab end |