Class: Inventory::Rake::Tasks::Inventory

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/inventory-rake-1.0/tasks/inventory.rb

Overview

Tasks related to the inventory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|?| ... } ⇒ Inventory

Sets up tasks based on INVENTORY, optionally yields the task object for further customization, then #defines the tasks.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :inventory (Inventory) — default: Inventory::Rake::Tasks.inventory

    The inventory to use

  • :pattern (String) — default: '{ext/**/*.{[ch],rb},{lib/test}/**/*.rb}'

    The pattern to use when looking for files not listed in inventory

Yields:

  • (?)

Yield Parameters:

  • task (self)


18
19
20
21
22
23
# File 'lib/inventory-rake-1.0/tasks/inventory.rb', line 18

def initialize(options = {})
  self.inventory = options.fetch(:inventory, Inventory::Rake::Tasks.inventory)
  self.pattern = options.fetch(:pattern, '{ext/**/*.{[ch],rb},{lib,test}/**/*.rb}')
  yield self if block_given?
  define
end

Instance Attribute Details

#inventory=(value) ⇒ Inventory (writeonly)

Returns The inventory to use: VALUE.

Parameters:

Returns:

  • (Inventory)

    The inventory to use: VALUE



45
46
47
# File 'lib/inventory-rake-1.0/tasks/inventory.rb', line 45

def inventory=(value)
  @inventory = value
end

#pattern=(value) ⇒ String (writeonly)

Returns The pattern to use: VALUE.

Parameters:

  • value (String)

Returns:

  • (String)

    The pattern to use: VALUE



49
50
51
# File 'lib/inventory-rake-1.0/tasks/inventory.rb', line 49

def pattern=(value)
  @pattern = value
end

Instance Method Details

#defineObject

Defines the following task:

<dl>

<dt>inventory:check</dt>
<dd>Check that the inventory is correct by looking for files not listed
in the inventory that match the pattern and for files listed in the
inventory that don’t exist; depends on distclean.</dd>

</dl>



33
34
35
36
37
38
39
40
41
# File 'lib/inventory-rake-1.0/tasks/inventory.rb', line 33

def define
  desc 'Check that the inventory is correct'
  task :'inventory:check' => :distclean do
    diff = ((Dir[@pattern] - @inventory.files).map{ |e| '%s: file not listed in inventory' % e } +
            @inventory.files.reject{ |e| File.exist? e }.map{ |e| '%s: file listed in inventory does not exist' % e })
    fail diff.join("\n") unless diff.empty?
    # TODO: puts 'inventory checks out' if verbose
  end
end