Class: AnnotateModel::ModelFile

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

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ ModelFile

Initializes a new ModelFile instance.



6
7
8
# File 'lib/annotate_model/model_file.rb', line 6

def initialize(file_path)
  @file_path = file_path
end

Instance Method Details

#model_nameString

Returns the model name corresponding to the model file path.

Examples:

For a file path "app/models/admin/user.rb", it returns "Admin::User".
For a file path "app/models/product.rb", it returns "Product".


21
22
23
# File 'lib/annotate_model/model_file.rb', line 21

def model_name
  @file_path.relative_path_from(Rails.root.join('app', 'models')).to_s.sub('.rb', '').camelize
end

#relative_pathObject



10
11
12
# File 'lib/annotate_model/model_file.rb', line 10

def relative_path
  @file_path.relative_path_from(Rails.root).to_s
end

#table_nameString

Returns the table name corresponding to the model file path.

Examples:

For a file path "app/models/admin/user.rb", it returns "admin_users".
For a file path "app/models/product.rb", it returns "products".


32
33
34
# File 'lib/annotate_model/model_file.rb', line 32

def table_name
  @file_path.relative_path_from(Rails.root.join('app', 'models')).to_s.sub('.rb', '').classify.tableize.sub('/', '_')
end

#to_sObject



36
37
38
# File 'lib/annotate_model/model_file.rb', line 36

def to_s
  @file_path.to_s
end