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