Class: Germinator::SeedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/germinator/seed_file.rb

Overview

A helper class to parse a seed file name and return the appropriate values

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SeedFile

Inititalize the class instance.

Parameters:

path => The full path of the seed file being parsed.



20
21
22
# File 'lib/germinator/seed_file.rb', line 20

def initialize path
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/germinator/seed_file.rb', line 11

def path
  @path
end

Instance Method Details

#basenameObject

Returns the base file name of the seed file.



28
29
30
# File 'lib/germinator/seed_file.rb', line 28

def basename
  Pathname.new(@path).basename.to_s
end

#class_nameObject

Returns the name of the class for the seed file.



63
64
65
# File 'lib/germinator/seed_file.rb', line 63

def class_name
  name.camelize
end

#nameObject

Returns the name portion of the seed file.



46
47
48
49
50
# File 'lib/germinator/seed_file.rb', line 46

def name
  parts = basename.split('_', 2)
  return "" if parts.length <= 1
  return parts[1].gsub(/\.rb/, "").to_s
end

#seed_nameObject

Returns the full seed name of the seed file (no path or extension).



55
56
57
# File 'lib/germinator/seed_file.rb', line 55

def seed_name
  "#{version}_#{name}"
end

#to_sObject

Override the to_s method to make it more readable.



71
72
73
# File 'lib/germinator/seed_file.rb', line 71

def to_s
  "[#{version}] #{class_name}"
end

#versionObject

Returns the version portion of the seed file.



36
37
38
39
40
# File 'lib/germinator/seed_file.rb', line 36

def version
  parts = basename.split('_', 2)
  return "" if parts.length === 0
  return parts[0]
end