Class: Saruman::Generators::Model

Inherits:
Thor::Group
  • Object
show all
Includes:
Base, Thor::Actions
Defined in:
lib/saruman/generators/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#app_design_frontend_base_layout_local_xml_path, #app_design_frontend_base_layout_path, #app_design_frontend_base_path, #app_design_frontend_base_template_namespace_path, #app_design_frontend_base_template_path, #author, #block_klass_name, #combined_namespace, #command, #config_has_tag?, #controller?, #controller_block_file_path, #controller_block_path, #controller_front_name, #controller_path, #controllers, #extension_base_path, #extension_config_file_path, #extension_config_path, #extension_current_version, #extension_name_lower, #extension_temp_path, #extension_upgrade_version, #global_config_basepath, #global_config_file_path, #helper?, #helper_path, #insert_tag_at_node, #insert_xml_at_node, #model?, #model_klass_name, #model_path, #models, #name, #name_lower, #namespace, #namespace_lower, #observer?, #observers, #read_extension_config, #resource_model_klass_name, #resource_model_name, #resource_model_path, #setup_base_path, #version, #write_extension_config

Class Method Details

.source_rootObject



12
13
14
# File 'lib/saruman/generators/model.rb', line 12

def self.source_root
  File.dirname(__FILE__) + "/model/templates"
end

Instance Method Details

#create_installer_upgradeObject



73
74
75
76
77
78
79
80
81
# File 'lib/saruman/generators/model.rb', line 73

def create_installer_upgrade
  if command.to_s == "extension"
    template("mysql4-install.php", "#{setup_base_path}/mysql4-install-#{version}.php")
  elsif command.to_s == "model"
    template("mysql4-install.php", "#{setup_base_path}/mysql4-upgrade-#{extension_current_version}-#{extension_upgrade_version}.php")
  else

  end
end

#create_model_directoryObject



30
31
32
# File 'lib/saruman/generators/model.rb', line 30

def create_model_directory
  empty_directory(model_path) unless File.directory?(model_path)
end

#create_modelsObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/saruman/generators/model.rb', line 61

def create_models
  models.each do |model|
    @model = model
    template("Model.php", "#{model_path}#{@model.name}.php")
    template("Resource_Model.php", "#{resource_model_path}#{@model.name}.php")
    if model.collection?
      empty_directory("#{resource_model_path}#{@model.name}/")
      template("Collection.php", "#{resource_model_path}#{@model.name}/Collection.php")
    end  
  end       
end

#load_buildersObject



26
27
28
# File 'lib/saruman/generators/model.rb', line 26

def load_builders
  @model_xml_config_builder = Saruman::ModelXmlConfigBuilder.new(models, self)
end

#modify_configObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/saruman/generators/model.rb', line 34

def modify_config
  
  @config = read_extension_config
  
  unless config_has_tag?("config global")
    insert_tag_at_node("global", "config")
  end
  
  unless config_has_tag?("config global models")
    insert_tag_at_node("models", "config global")
  end
  
  unless config_has_tag?("models #{name_lower}")
    insert_xml_at_node(@model_xml_config_builder.config_global_models_model_xml, "config models")
    insert_xml_at_node(@model_xml_config_builder.config_models_resource_xml, "config models")
  else
    insert_xml_at_node(@model_xml_config_builder.config_models_resource_entities_xml, "#{name_lower}_mysql4 entities")
  end
  
  unless config_has_tag?("resources")
    insert_xml_at_node(@model_xml_config_builder.config_global_resources_xml, "config global resources")
  end
  
  write_extension_config
  
end

#validate_extensionObject



16
17
18
19
20
21
22
23
24
# File 'lib/saruman/generators/model.rb', line 16

def validate_extension
  unless File.directory?("#{extension_base_path}")
    @error = "error"
  end

  unless File.exist?("#{extension_config_path}/config.xml")
    @error = "error"
  end
end