Class: ConfigScripts::Scripts::ScriptHistory

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/config_scripts/scripts/script_history.rb

Overview

This class models a record of a script being run.

This uses the config_scripts table to record its histories.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#nameString

The name of the script, which will be its timestamp.

Returns:

  • (String)


# File 'lib/config_scripts/scripts/script_history.rb', line 9

Class Method Details

.entries_for_timestamp(timestamp) ⇒ Relation<ScriptHistory>

This method gets all of the entries that have a timestamp as their name.

Returns:



15
16
17
# File 'lib/config_scripts/scripts/script_history.rb', line 15

def self.entries_for_timestamp(timestamp)
  self.where(:name => timestamp)
end

.record_timestamp(timestamp) ⇒ ScriptHistory

This method records that we have run a script with a timestamp.

Returns:



27
28
29
# File 'lib/config_scripts/scripts/script_history.rb', line 27

def self.record_timestamp(timestamp)
  self.entries_for_timestamp(timestamp).first_or_create
end

.remove_timestamp(timestamp) ⇒ Array<ScriptHistory>

This method removes all records that we have run a script with a timestamp.

Returns:



34
35
36
# File 'lib/config_scripts/scripts/script_history.rb', line 34

def self.remove_timestamp(timestamp)
  self.entries_for_timestamp(timestamp).destroy_all
end

.script_was_run?(timestamp) ⇒ Boolean

This method determines if we have run a script with a timestamp.

Returns:

  • (Boolean)


21
22
23
# File 'lib/config_scripts/scripts/script_history.rb', line 21

def self.script_was_run?(timestamp)
  self.entries_for_timestamp(timestamp).any?
end