Class: OneOff::File

Inherits:
Object
  • Object
show all
Includes:
GlobalID::Identification
Defined in:
lib/one_off/file.rb

Constant Summary collapse

REGEX =
/\A(\d{14})_(\w+)\z/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ File

Returns a new instance of File.



24
25
26
# File 'lib/one_off/file.rb', line 24

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



22
23
24
# File 'lib/one_off/file.rb', line 22

def filename
  @filename
end

Class Method Details

.allObject



10
11
12
13
14
15
# File 'lib/one_off/file.rb', line 10

def all
  Dir.glob('db/one_off/*.rb', base: Rails.root)
    .map { |f| ::File.basename(f, '.rb') }
    .select { |f| REGEX.match(f) }
    .map { |f| new(f) }
end

.find(id) ⇒ Object



17
18
19
# File 'lib/one_off/file.rb', line 17

def find(id)
  all.find { |file| file.id == id.to_i }
end

Instance Method Details

#file_name_matchObject



28
29
30
# File 'lib/one_off/file.rb', line 28

def file_name_match
  @file_name_match ||= REGEX.match(filename)
end

#task_nameObject



38
39
40
# File 'lib/one_off/file.rb', line 38

def task_name
  file_name_match[2]
end

#versionObject Also known as: id



32
33
34
# File 'lib/one_off/file.rb', line 32

def version
  file_name_match[1].to_i
end