Class: Columns::Application

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

Overview

The tool chain.

Instance Method Summary collapse

Constructor Details

#initialize(schema_dir, models_dir) ⇒ Application

Creates a new Application.

See Columns.execute for arguments.

Raises SystemExit if it can’t find the ‘schema.rb`.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/columns.rb', line 39

def initialize(schema_dir, models_dir)
  @models_dir = models_dir
  schema_path = File.expand_path(File.join(schema_dir,'schema.rb'))

  unless File.exists?(schema_path)
    puts "COLUMNS ERROR : #{schema_path} doesn't exist!"
    exit 1
  end
  table = Table.new(File.read(schema_path))

  raw_data_objects = []
  table.names.each do |name|
    raw_data_objects << RawData.new(name, table.content_for(name))
  end

  @model_data_objects = raw_data_objects.map do |object|
    ModelData.new(object)
  end
end

Instance Method Details

#executeObject

Cleans then writes models.

Returns nothing.



62
63
64
65
66
67
68
69
# File 'lib/columns.rb', line 62

def execute
  writer = ModelWriter.new(path: @models_dir)
  @model_data_objects.each do |object|
    path = File.expand_path(File.join(@models_dir, object.name) + '.rb')
    ModelCleaner.clean(path)
    writer.add_info(object)
  end
end