Class: Columns::ModelData

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

Overview

Stores data about a model.

Model name


Usually a table is named with a plural, like ‘users’. The corresponding model name is in singular, like ‘user’.

Model content


We want a «ready to paste» content.

So, for example, if the raw content is:

integer "foo"

what we want is something like this:

#  integer "foo"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data) ⇒ ModelData

Public: Creates a new ModelData.

raw_data - A RawData object.



35
36
37
38
39
40
41
# File 'lib/columns/model_data.rb', line 35

def initialize(raw_data)
  @name = raw_data.name.singularize

  contents = raw_data.content.split("\n")
  contents.map! {|line| "#  #{line.gsub(/^\s*t\./, '')}\n" }
  @content = contents.join
end

Instance Attribute Details

#contentObject (readonly)

Public: Get a String formatted content.



30
31
32
# File 'lib/columns/model_data.rb', line 30

def content
  @content
end

#nameObject (readonly)

Public: Get the String model’s name. For a model ‘app/models/user.rb`, the model’s name will be ‘user`.



27
28
29
# File 'lib/columns/model_data.rb', line 27

def name
  @name
end