Class: Tools::Actions::Create

Inherits:
Object
  • Object
show all
Includes:
Support::Execution, Support::Manifest
Defined in:
lib/tools/actions/create.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::Execution

#execute_command

Constructor Details

#initialize(manifest:, announce:, source:, output:, piece_size:, privacy:) ⇒ Create

Create creates .torrent files for all files found in its manifest.

Parameters:

  • manifest (String)

    Path to JSON configuration file that lists all files to be proceesed.

  • announce (String)

    Announce URL of the primary tracker for this torrent.

  • source (String)

    Path to the directory where source files will be located.

  • output (String)

    Path to the directory where completed .torrent files will be saved.

  • piece_size (Fixnum)

    BitTorrent piece size, as a power of 2. e.g. 18 = piece size of 256kb because 2**18 is 256kb

  • privacy (Boolean)

    Should this torrent be private?



19
20
21
22
23
24
25
26
27
# File 'lib/tools/actions/create.rb', line 19

def initialize(manifest:, announce:, source:, output:, piece_size:, privacy:)
  @announce = announce
  @source = source
  @output = output
  @piece_size = piece_size
  @privacy = privacy

  @files = extract_files(manifest)
end

Instance Attribute Details

#announceObject (readonly)

Returns the value of attribute announce.



10
11
12
# File 'lib/tools/actions/create.rb', line 10

def announce
  @announce
end

#filesObject (readonly)

Returns the value of attribute files.



10
11
12
# File 'lib/tools/actions/create.rb', line 10

def files
  @files
end

#outputObject (readonly)

Returns the value of attribute output.



10
11
12
# File 'lib/tools/actions/create.rb', line 10

def output
  @output
end

#piece_sizeObject (readonly)

Returns the value of attribute piece_size.



10
11
12
# File 'lib/tools/actions/create.rb', line 10

def piece_size
  @piece_size
end

#privacyObject (readonly)

Returns the value of attribute privacy.



10
11
12
# File 'lib/tools/actions/create.rb', line 10

def privacy
  @privacy
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/tools/actions/create.rb', line 10

def source
  @source
end

Instance Method Details

#executeObject

Create a .torrent file for every file in the manifest



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tools/actions/create.rb', line 30

def execute
  create_output_directory

  files.each do |file_name|
    # Full relative path to the source file
    infile_path = source_path(file_name)
    # File name of output file
    outfile_name = torrent_name(file_name)
    # Full relative path to output file
    outfile_path = output_path(outfile_name)

    if can_create_torrent?(infile_path)
      make_torrent(infile_path, outfile_path)

      puts "√ #{outfile_name}"
    end
  end
end