Class: SqlMigrations::File

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_migrations/file.rb

Overview

Class that represents script file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, database, type) ⇒ File

Returns a new instance of File.



7
8
9
10
11
12
13
14
15
# File 'lib/sql_migrations/file.rb', line 7

def initialize(path, database, type)
  @path     = path
  @database = database
  @type     = type.to_s

  @file, @base, @parent = elements(path)
  @date, @time, @name = match(@file) if @file
  @datetime = (@date.to_s + @time.to_s).to_i
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



5
6
7
# File 'lib/sql_migrations/file.rb', line 5

def database
  @database
end

#dateObject (readonly)

Returns the value of attribute date.



5
6
7
# File 'lib/sql_migrations/file.rb', line 5

def date
  @date
end

#datetimeObject (readonly)

Returns the value of attribute datetime.



5
6
7
# File 'lib/sql_migrations/file.rb', line 5

def datetime
  @datetime
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/sql_migrations/file.rb', line 5

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/sql_migrations/file.rb', line 5

def path
  @path
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/sql_migrations/file.rb', line 5

def time
  @time
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/sql_migrations/file.rb', line 5

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
# File 'lib/sql_migrations/file.rb', line 25

def ==(other)
  datetime == other.datetime
end

#contentObject



21
22
23
# File 'lib/sql_migrations/file.rb', line 21

def content
  ::File.read(@path)
end

#to_sObject



29
30
31
# File 'lib/sql_migrations/file.rb', line 29

def to_s
  @file.to_s
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  [@name, @time, @date, @database, directories?].all?
end