Class: Openasn::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/openasn/install/install_generator.rb

Overview

rails generate openasn:install

Creates the initializer and wires the daily update job into Solid Queue's recurring.yml when present. No migrations — OpenASN is file-based by design (storage/openasn/), nothing touches your DB.

Instance Method Summary collapse

Instance Method Details

#create_initializerObject



15
16
17
# File 'lib/generators/openasn/install/install_generator.rb', line 15

def create_initializer
  template "openasn.rb", "config/initializers/openasn.rb"
end

#display_post_install_messageObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/generators/openasn/install/install_generator.rb', line 44

def display_post_install_message
  say ""
  say "\tThe `openasn` gem has been successfully installed!", :green
  say ""
  say "OpenASN works out of the box: a data seed is bundled with the gem and"
  say "refreshes itself daily via OpenASN::UpdateJob (data flows through GitHub"
  say "Releases — never through gem updates)."
  say ""
  say "To complete the setup:"
  say "  1. Review config/initializers/openasn.rb (defaults are production-ready)."
  say "  2. Make sure a queue backend runs OpenASN::UpdateJob daily (done for you"
  say "     if you use Solid Queue's recurring.yml)."
  say "  3. Start in SHADOW MODE — log verdicts, block nothing:"
  say ""
  say "       # e.g. in your signups controller:"
  say "       Rails.logger.info(openasn: OpenASN.lookup(request.remote_ip).to_h)"
  say ""
  say "     After a week or two of data, decide your own thresholds. Remember:"
  say "     a residential verdict is absence of evidence, not proof of innocence,"
  say "     and :relay/:cgnat/:mobile are real humans — never hard-block them.", :yellow
  say ""
end

#wire_recurring_jobObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/openasn/install/install_generator.rb', line 19

def wire_recurring_job
  recurring = "config/recurring.yml"
  unless File.exist?(File.expand_path(recurring, destination_root))
    say_status :skipped, "#{recurring} not found — schedule OpenASN::UpdateJob with your own scheduler (see README)", :yellow
    return
  end

  if File.read(File.expand_path(recurring, destination_root)).include?("OpenASN::UpdateJob")
    say_status :identical, "#{recurring} already schedules OpenASN::UpdateJob", :blue
    return
  end

  # 4:12am UTC: after the nightly data build (03:17 UTC) completes,
  # off-hour to be kind to the Tier B upstreams.
  append_to_file recurring, <<~YAML

    # Added by `rails g openasn:install` — daily IP-origin data refresh
    production:
      openasn_update:
        class: OpenASN::UpdateJob
        queue: default
        schedule: every day at 4:12am UTC
  YAML
end