class Model

Attributes

file_contents[RW]
file_path[RW]

Public Class Methods

from_file(file) click to toggle source
# File lib/relationships/model.rb, line 4
def self.from_file(file)
  Model.new file: file
end
new(args = {}) click to toggle source
# File lib/relationships/model.rb, line 8
def initialize(args = {})
  @file_path = args[:file]
  if File.directory? file_path
    model_files = Dir[Pathname.new(file_path)]
    models = model_files.map do |model_file|
      Model.from_file model_file
    end
  else
    @file_contents = File.read file_path if file_path 
  end
end

Public Instance Methods

class_name() click to toggle source
# File lib/relationships/model.rb, line 28
def class_name
  file_name[/\w+/].camelize
end
file_name() click to toggle source
# File lib/relationships/model.rb, line 24
def file_name
  file_path[/\w+\.rb/]
end
relationships() click to toggle source
# File lib/relationships/model.rb, line 20
def relationships
  @relationships ||= extract_relationships
end

Private Instance Methods

extract_relationships() click to toggle source
# File lib/relationships/model.rb, line 34
def extract_relationships
  @file_contents.scan /belongs_to.+$|has_many.+$|has_one.+$|has_and_belongs_to_many.+$/
end