class Tennpipes::Generators::Model
Responsible for generating new models for the specified ORM component.
Public Class Methods
source_root()
click to toggle source
# File lib/tennpipes-init/generators/model.rb, line 9 def self.source_root; File.expand_path(File.dirname(__FILE__)); end
Public Instance Methods
create_model()
click to toggle source
Execute the model generation.
# File lib/tennpipes-init/generators/model.rb, line 31 def create_model app = options[:app] return unless valid_model_for?(app) include_component_module_for(:test) migration_name = "create_#{name.pluralize.underscore}" apply_default_fields fields create_model_file(name, :fields => fields, :app => app) generate_model_test(name) if test? create_model_migration(migration_name, name, fields) unless options[:skip_migration] end
Private Instance Methods
check_orm()
click to toggle source
Alert if there is not an ORM Adapter
# File lib/tennpipes-init/generators/model.rb, line 86 def check_orm return true if include_component_module_for(:orm) say "<= You need an ORM adapter for run this generator. Sorry!" raise SystemExit end
correct_path?()
click to toggle source
Check app path
# File lib/tennpipes-init/generators/model.rb, line 96 def correct_path? return true if in_app_root? say 'You are not at the root of a Tennpipes application! (config/boot.rb not found)' false end
has_invalid_fields?()
click to toggle source
Check if the fields are valid
# File lib/tennpipes-init/generators/model.rb, line 105 def has_invalid_fields? if invalids = invalid_fields(fields) say 'Invalid field name:', :red say " #{invalids.join(", ")}" end end
model_name_already_exists?()
click to toggle source
Return false if the model name is being used
# File lib/tennpipes-init/generators/model.rb, line 73 def model_name_already_exists? @camel_name = name.to_s.underscore.camelize @project_name = "" @project_name = fetch_project_name return false unless already_exists?(@camel_name, @project_name) true end
valid_model_for?(app)
click to toggle source
Validate model characteristics Alert if the model name is being used
# File lib/tennpipes-init/generators/model.rb, line 49 def valid_model_for?(app) self.destination_root = options[:root] return false unless correct_path? check_app_existence(app) if options[:destroy] self.behavior = :revoke else unless options[:force] say "#{@camel_name} already exists." say "Please, change the name." return false end end if model_name_already_exists? return false if has_invalid_fields? check_orm end