Class: ConventionalModels::Table

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, columns, conventions) ⇒ Table

Returns a new instance of Table.



5
6
7
8
9
10
11
12
13
# File 'lib/conventional_models/table.rb', line 5

def initialize(name, columns, conventions)
  @name = name
  @columns = columns
  @lines = []
  @belongs_to_names = []
  @config = conventions
  
  apply_conventions
end

Instance Attribute Details

#belongs_to_namesObject

Returns the value of attribute belongs_to_names.



3
4
5
# File 'lib/conventional_models/table.rb', line 3

def belongs_to_names
  @belongs_to_names
end

#class_nameObject

Returns the value of attribute class_name.



3
4
5
# File 'lib/conventional_models/table.rb', line 3

def class_name
  @class_name
end

#columnsObject

Returns the value of attribute columns.



3
4
5
# File 'lib/conventional_models/table.rb', line 3

def columns
  @columns
end

#linesObject

Returns the value of attribute lines.



3
4
5
# File 'lib/conventional_models/table.rb', line 3

def lines
  @lines
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/conventional_models/table.rb', line 3

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



15
16
17
# File 'lib/conventional_models/table.rb', line 15

def ==(other)
  @name == other.name
end

#codeObject



19
20
21
# File 'lib/conventional_models/table.rb', line 19

def code
  "class ::#{@class_name} < #{@config.base_class}\n#{@lines.map{|l| "  #{l}"}.join("\n")}\nend"
end

#conventional_name?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/conventional_models/table.rb', line 23

def conventional_name?
  @name.tableize == @name
end