Class: Xf::Generators::ConcernGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/xf/concern/concern_generator.rb

Instance Method Summary collapse

Instance Method Details

#generate_concernObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/xf/concern/concern_generator.rb', line 45

def generate_concern
  models.reverse.each do |model|
    @model_name = model.camelize

    model(File.join("app/models", "#{file_path}.rb"), "include Models::#{class_name}::#{@model_name}Methods\n")

    template "concern_model.rb",  "lib/models/#{file_path}/#{model}_methods.rb"      
    template "concern_spec.rb",   "spec/lib/models/#{file_path}/#{model}_methods_spec.rb"
  end
end

#validationObject

Raises:

  • (NameError)


41
42
43
# File 'lib/generators/xf/concern/concern_generator.rb', line 41

def validation
  raise(NameError, "#{file_path.classify} model was not found.") unless File.exists?(File.join("app/models", "#{file_path}.rb"))
end