Class: Thor::Actions::Resource

Inherits:
Object
  • Object
show all
Includes:
Angus::FileHandler, Angus::HelperMethods
Defined in:
lib/angus/generator/thor/resource.rb

Overview

:nodoc:

Constant Summary collapse

FILE_MAPPINGS =
{
  'resources/resource.rb.erb' => -> command, name { "#{command.underscore(command.classify(name))}.rb" },
  'definitions/operations.yml.erb' => -> command, _ { File.join(command.underscore(command.resource_name), 'operations.yml') }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Angus::FileHandler

#copy_erb_file, #filename_resolver, #is_erb?

Methods included from Angus::HelperMethods

#classify, #pluralize, #underscore

Constructor Details

#initialize(base, name, actions, config) ⇒ Resource

Creates a new resource.

Parameters:

  • base (Thor::Base)

    A Thor::Base instance



35
36
37
38
39
40
41
42
43
# File 'lib/angus/generator/thor/resource.rb', line 35

def initialize(base, name, actions, config)
  @base, @config   = base, { :verbose => true }.merge(config)

  self.resource_name = pluralize(name)
  self.actions       = actions
  self.resource_directory   = File.join(Dir.pwd, Angus::CommandProcessor::RESOURCES_DIR)
  self.definition_directory = File.join(Dir.pwd, Angus::CommandProcessor::DEFINITIONS_DIR)
  self.service_directory    = File.join(Dir.pwd, Angus::CommandProcessor::SERVICES_DIR)
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



29
30
31
# File 'lib/angus/generator/thor/resource.rb', line 29

def actions
  @actions
end

#baseObject

Returns the value of attribute base.



29
30
31
# File 'lib/angus/generator/thor/resource.rb', line 29

def base
  @base
end

#configObject

Returns the value of attribute config.



29
30
31
# File 'lib/angus/generator/thor/resource.rb', line 29

def config
  @config
end

#definition_directoryObject

Returns the value of attribute definition_directory.



29
30
31
# File 'lib/angus/generator/thor/resource.rb', line 29

def definition_directory
  @definition_directory
end

#resource_directoryObject

Returns the value of attribute resource_directory.



29
30
31
# File 'lib/angus/generator/thor/resource.rb', line 29

def resource_directory
  @resource_directory
end

#resource_nameObject

Returns the value of attribute resource_name.



29
30
31
# File 'lib/angus/generator/thor/resource.rb', line 29

def resource_name
  @resource_name
end

#service_directoryObject

Returns the value of attribute service_directory.



29
30
31
# File 'lib/angus/generator/thor/resource.rb', line 29

def service_directory
  @service_directory
end

Instance Method Details

#invoke!Object



45
46
47
48
49
50
51
52
# File 'lib/angus/generator/thor/resource.rb', line 45

def invoke!
  base.empty_directory(resource_directory)
  base.empty_directory(definition_directory)

  copy_erb_file('resources/resource.rb.erb', underscore(resource_name), resource_directory)
  copy_erb_file('definitions/operations.yml.erb', underscore(resource_name), definition_directory)
  insert_into_services("    register :#{underscore(resource_name)}\n")
end

#revoke!Object



54
55
56
# File 'lib/angus/generator/thor/resource.rb', line 54

def revoke!

end