class Nucleon::Action::Plugin::Create
Public Class Methods
describe()
click to toggle source
Calls superclass method
# File lib/nucleon/action/plugin/create.rb 10 def self.describe 11 super(:plugin, :create, 10) 12 end
Public Instance Methods
arguments()
click to toggle source
# File lib/nucleon/action/plugin/create.rb 63 def arguments 64 [ :type, :name ] 65 end
configure()
click to toggle source
Calls superclass method
# File lib/nucleon/action/plugin/create.rb 21 def configure 22 super do 23 codes :no_template_file, 24 :template_file_parse_failed, 25 :plugin_already_exists, 26 :plugin_save_failed 27 28 register_str :type, :action do |value| 29 namespace = nil 30 components = value.to_s.split(':::') 31 32 if components.size > 1 33 namespace = components[0].to_sym 34 value = components[1] 35 end 36 value = value.to_sym 37 38 Nucleon.namespaces.each do |plugin_namespace| 39 if ! namespace || namespace == plugin_namespace 40 if Nucleon.types(plugin_namespace).include?(value) 41 @plugin_namespace = plugin_namespace 42 @plugin_type = value 43 end 44 end 45 end 46 @plugin_namespace ? true : false 47 end 48 register_array :name, nil 49 50 register_bool :save 51 register_bool :interpolate, true 52 53 register_directory :template_path 54 end 55 end
execute()
click to toggle source
Calls superclass method
# File lib/nucleon/action/plugin/create.rb 70 def execute 71 super do |node| 72 ensure_network do 73 require 'erubis' 74 75 type = settings[:type].to_sym 76 name = settings[:name] 77 78 unless template_path = settings.delete(:template_path) 79 template_path = File.join(File.dirname(__FILE__), 'template') 80 end 81 82 templates = Dir.glob("#{template_path}/**/*.erb") 83 template = nil 84 85 templates.each do |template_file| 86 if template_file =~ /#{@plugin_namespace}\.#{@plugin_type}\.erb/ 87 template = template_file 88 end 89 end 90 91 if template 92 template_contents = Util::Disk.read(template) 93 94 unless template_contents 95 error('parse_failed', { :file => template }) 96 myself.status = code.template_file_parse_failed 97 next 98 end 99 template = template_contents 100 end 101 102 unless template 103 error('no_template', { :file => "#{template_path}#{File::SEPARATOR}#{@plugin_namespace}.#{@plugin_type}.erb" }) 104 myself.status = code.no_template_file 105 next 106 end 107 108 save_path = File.join(network.directory, 'lib', @plugin_namespace.to_s, @plugin_type.to_s) 109 save_file = File.join(save_path, name.join(File::SEPARATOR) + '.rb') 110 plugin_file = nil 111 112 if File.exists?(save_file) 113 error('provider_exists', { :file => save_file }) 114 myself.status = code.plugin_already_exists 115 next 116 end 117 118 settings.import({ 119 :plugin_class => name.pop, 120 :plugin_groups => name 121 }) 122 123 renderer = Erubis::Eruby.new(template) 124 parse = true 125 126 while(parse) 127 begin 128 plugin_file = renderer.result(settings.export) 129 parse = false 130 131 rescue NameError => error 132 settings.set(error.name, nil) 133 134 rescue => error 135 raise error 136 end 137 end 138 139 if settings.delete(:save) 140 # Save template to file within network project 141 save_directory = File.dirname(save_file) 142 143 FileUtils.mkdir_p(save_directory) 144 145 if Util::Disk.write(save_file, plugin_file) 146 success('saved', { :file => save_file }) 147 else 148 error('save_failed', { :file => save_file }) 149 myself.status = code.plugin_save_failed 150 end 151 else 152 info('plugin_file', { :file => blue(save_file) }) 153 # Render template ONLY (testing) 154 if settings.delete(:interpolate) 155 puts green(plugin_file) 156 else 157 puts green(template) 158 end 159 end 160 end 161 end 162 end
ignore()
click to toggle source
# File lib/nucleon/action/plugin/create.rb 59 def ignore 60 node_ignore 61 end
strict?()
click to toggle source
# File lib/nucleon/action/plugin/create.rb 17 def strict? 18 false # Allow extra settings 19 end