Class: MnoEnterprise::DatabaseExtensionGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/mno_enterprise/database_extension/database_extension_generator.rb

Instance Method Summary collapse

Instance Method Details

#check_class_collisionObject

Check the class we want to extend doesn’t exist



22
23
24
25
26
# File 'lib/generators/mno_enterprise/database_extension/database_extension_generator.rb', line 22

def check_class_collision
  @model_name = "MnoEnterprise::#{class_name}Extension"
  @model_name.constantize rescue nil # To preload class in dev?
  class_collisions @model_name
end

#check_class_existsObject

Check the class we want to extend exists



7
8
9
10
11
12
# File 'lib/generators/mno_enterprise/database_extension/database_extension_generator.rb', line 7

def check_class_exists
  klass = "MnoEnterprise::#{class_name}"
  klass.constantize
rescue NameError
   raise Thor::Error, "The class '#{klass}' does not exist in Maestrano Enterprise"
end

#check_class_is_decorator_readyObject



14
15
16
17
18
19
# File 'lib/generators/mno_enterprise/database_extension/database_extension_generator.rb', line 14

def check_class_is_decorator_ready
  klass = "MnoEnterprise::Concerns::Models::#{class_name}"
  klass.constantize
rescue NameError
  raise Thor::Error, "The class '#{class_name}' is not decorator ready. Please extract it to #{klass}."
end

#generate_extension_modelObject



28
29
30
31
# File 'lib/generators/mno_enterprise/database_extension/database_extension_generator.rb', line 28

def generate_extension_model
  params = "#{@model_name} #{file_name}_uid:string:uniq " + fields.join(' ') + " --no-fixture -t rspec"
  generate "model", params
end

#generate_mnoe_modelObject



33
34
35
# File 'lib/generators/mno_enterprise/database_extension/database_extension_generator.rb', line 33

def generate_mnoe_model
  template 'model.rb', File.join('app/models/mno_enterprise', "#{file_name}.rb")
end