Class: NeocitiesRed::Services::Site::Pusher

Inherits:
Object
  • Object
show all
Defined in:
lib/neocities_red/services/site/pusher.rb

Overview

Recursively uploads a local directory to the Neocities site.

Orchestrates the full push workflow:

  1. Validates the root path
  2. Optionally prunes remote files not present locally
  3. Collects all files via glob
  4. Applies .gitignore rules, dotfile filtering, exclusions, and optimized (hash-based) filtering
  5. Uploads remaining files in parallel via a worker pool

Examples:

Basic push

pusher = NeocitiesRed::Services::Site::Pusher.new(
  client, display,
  root: ".", no_gitignore: false, ignore_dotfiles: false,
  exclude: [], dry_run: false, prune: false, optimized: false
)
pusher.push

See Also:

Constant Summary collapse

MAX_THREADS =

Warning: a high thread count may be flagged as DDOS-like traffic by Neocities, potentially resulting in a temporary IP ban.

Returns:

  • (Integer)

    maximum concurrent upload threads.

5

Instance Method Summary collapse

Constructor Details

#initialize(client, display, root:, no_gitignore:, ignore_dotfiles:, exclude:, dry_run:, prune:, optimized:) ⇒ Pusher

Returns a new instance of Pusher.

Parameters:

  • client (NeocitiesRed::Client)

    authenticated API client

  • display (NeocitiesRed::CliDisplay)

    output helper

  • root (String)

    local directory path to push

  • no_gitignore (Boolean)

    when true, ignores .gitignore rules

  • ignore_dotfiles (Boolean)

    when true, skips files starting with "."

  • exclude (Array<String>)

    additional paths to exclude from upload

  • dry_run (Boolean)

    when true, simulates the push without uploading

  • prune (Boolean)

    when true, deletes remote files not present locally

  • optimized (Boolean)

    when true, skips files whose SHA1 matches the server



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/neocities_red/services/site/pusher.rb', line 47

def initialize(client, display, root:, no_gitignore:, ignore_dotfiles:, exclude:, dry_run:, prune:, optimized:)
  @client = client
  @display = display
  @root = root
  @no_gitignore = no_gitignore
  @ignore_dotfiles = ignore_dotfiles
  @exclude = exclude
  @dry_run = dry_run
  @prune = prune
  @optimized = optimized
end

Instance Method Details

#pushvoid

This method returns an undefined value.

Executes the full push workflow.

Raises:

  • (ArgumentError)

    if the root path does not exist or is not a directory



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/neocities_red/services/site/pusher.rb', line 63

def push
  root_path = Pathname(@root)
  validate_root_path!(root_path)

  @display.display_dry_run_notice if @dry_run
  prune_remote_files if @prune

  excluded_files = Services::Common::Exclusions.build(@exclude)

  Dir.chdir(root_path) do
    paths = Dir.glob(::File.join("**", "*"), ::File::FNM_DOTMATCH)

    paths = apply_gitignore(paths) unless @no_gitignore
    excluded_files += paths.select { |path| path.start_with?(".") } if @ignore_dotfiles
    excluded_files += optimized_exclusions(paths) if @optimized

    filtered_paths = paths.difference(excluded_files).map { |path| Pathname(path) }
    upload_files(filtered_paths)
  end
end