Class: SqlMigrations::SqlScript
- Inherits:
-
Object
- Object
- SqlMigrations::SqlScript
- Defined in:
- lib/sql_migrations/sql_script.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(db) ⇒ Object
-
#initialize(path, opts) ⇒ SqlScript
constructor
A new instance of SqlScript.
Constructor Details
#initialize(path, opts) ⇒ SqlScript
Returns a new instance of SqlScript.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/sql_migrations/sql_script.rb', line 6 def initialize(path, opts) @date = opts[:date] @time = opts[:time] @name = opts[:name] @path = opts[:path] @db_name = opts[:db_name] @content = IO.read(path) @type = self.class.name.downcase.split('::').last @datetime = (@date + @time).to_i end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
4 5 6 |
# File 'lib/sql_migrations/sql_script.rb', line 4 def date @date end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/sql_migrations/sql_script.rb', line 4 def name @name end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
4 5 6 |
# File 'lib/sql_migrations/sql_script.rb', line 4 def time @time end |
Class Method Details
.find(db_name, type) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sql_migrations/sql_script.rb', line 34 def self.find(db_name, type) scripts = [] Find.find(Dir.pwd) do |path| if !db_name.is_a? Array then db_name = [ db_name ] end file_date, file_time, file_name, file_db = self.(db_name, type, path) next unless file_name scripts << self.new(path, date: file_date, time: file_time, name: file_name, db_name: file_db) end scripts.sort_by { |file| (file.date + file.time).to_i } end |
Instance Method Details
#execute(db) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sql_migrations/sql_script.rb', line 17 def execute(db) @database = db return unless is_new? begin @database.db.transaction do @benchmark = Benchmark.measure do @database.db.run @content end end rescue puts "[-] Error while executing #{@type} #{@name} !" raise else on_success end end |