Class: App
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
Instance Method Summary collapse
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
9 10 11 |
# File 'lib/tern/app.rb', line 9 def app_name @app_name end |
Instance Method Details
#generate(type, name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tern/app.rb', line 43 def generate(type, name) unless File.exist?('config.yml') say 'This directory does not appear to be a Tern project. config.yml not found.', :red return end case type when 'a', 'alteration' current_version = Dir.entries('alterations').map do |f| f =~ /^(\d+)_.*.sql$/ ? $1.to_i : 0 end.max zero_padded_next_version = (current_version+1).to_s.rjust(3, "0") file_name = "#{zero_padded_next_version}_#{name}.sql" copy_file "change.sql", "alterations/#{file_name}" when 'd', 'definition' file_name = "#{name}.sql" copy_file "change.sql", "definitions/#{file_name}" say "Remember to add #{file_name} in your sequence.yml file." else say "#{type} is not a valid TYPE", :red end end |
#migrate ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tern/app.rb', line 23 def migrate require 'yaml' unless File.exist?('config.yml') say 'This directory does not appear to be a Tern project. config.yml not found.' return end config = YAML.load(File.read('config.yml')) ::Kernel.const_set("DB", Sequel.connect(config['environments'][["environment"]])) # using const_set to avoid dynamic constant assignment error begin tern = Tern.new(config['alterations']['table'], config['alterations']['column'], config['definitions']['table']) tern.migrate(:version => ["alteration_version"], :sequences => ["definition_sequences"]) rescue TernError say $!, :red end end |
#new(path) ⇒ Object
12 13 14 15 16 |
# File 'lib/tern/app.rb', line 12 def new(path) self.app_name = File.basename path self.destination_root = path directory "new", "." end |