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

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

Constant Summary collapse

MAX_THREADS =

warning - the big quantity of working threads could be considered like-a DDOS. Your ip-address could get banned on neocities for a few days.

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.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/neocities_red/services/site/pusher.rb', line 14

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

#pushObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/neocities_red/services/site/pusher.rb', line 26

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 = build_push_exclusions(@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