Class: Pinspec::Analyzer::AppProfileReader

Inherits:
Object
  • Object
show all
Includes:
Source
Defined in:
lib/pinspec/analyzer/app_profile_reader.rb

Constant Summary collapse

RAILS_FLOOR =
"6.0"
FLOOR_APIS =
[
  "insert_all - importing a sampled row without firing validations or callbacks",
  "connects_to - detecting a second writing database",
  "ActiveSupport::CurrentAttributes#reset_all - clearing state between cases"
].freeze
HELPER_PATHS =
[
  "spec/rails_helper.rb",
  "spec/spec_helper.rb",
  "spec/support/**/*.rb",
  "test/test_helper.rb",
  "config/environments/test.rb"
].freeze
MODEL_GLOB =
"app/models/**/*.rb"
MODEL_MACROS =
{
  after_commit:         :after_commit,
  after_create_commit:  :after_commit,
  after_update_commit:  :after_commit,
  after_destroy_commit: :after_commit,
  after_save_commit:    :after_commit,
  default_scope:        :default_scope,
  acts_as_tenant:       :acts_as_tenant,
  has_paper_trail:      :paper_trail,
  has_one_attached:     :active_storage,
  has_many_attached:    :active_storage,
  mount_uploader:       :carrierwave,
  has_attached_file:    :paperclip,
  connects_to:          :connects_to,
  acts_as_paranoid:     :paranoia
}.freeze
CURRENT_ATTRIBUTES_BASE =
"ActiveSupport::CurrentAttributes"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_root) ⇒ AppProfileReader

Returns a new instance of AppProfileReader.



54
55
56
# File 'lib/pinspec/analyzer/app_profile_reader.rb', line 54

def initialize(app_root)
  @root = app_root
end

Class Method Details

.read(app_root = ".", enforce_floor: true) ⇒ Object



49
50
51
# File 'lib/pinspec/analyzer/app_profile_reader.rb', line 49

def read(app_root = ".", enforce_floor: true)
  new(app_root).read(enforce_floor: enforce_floor)
end

Instance Method Details

#read(enforce_floor: true) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/pinspec/analyzer/app_profile_reader.rb', line 58

def read(enforce_floor: true)
  @notes    = []
  @findings = []

  gems = read_gemfile_lock
  scan_models
  rails_version = version_of(gems, "rails") || version_of(gems, "activerecord")
  floor_ok      = floor_ok?(rails_version)

  enforce_floor!(rails_version) if enforce_floor && floor_ok == false

  AppProfile.new(
    rails_version:          rails_version,
    ruby_version:           @ruby_version,
    rails_floor_ok:         floor_ok,
    auth:                   auth_for(gems),
    authz:                  authz_for(gems),
    tenancy:                tenancy_for(gems),
    soft_delete:            soft_delete_for(gems),
    versioning:             gem?(gems, "paper_trail") ? :paper_trail : :none,
    flags:                  gem?(gems, "flipper") ? :flipper : :none,
    attachments:            attachments_for(gems),
    multi_db:               multi_db?,
    spring:                 gem?(gems, "spring"),
    model_findings:         @findings,
    default_locale:         detect_locale,
    default_zone:           detect_zone,
    db_cleaner:             detect_db_cleaner_strategy(gems),
    transactional_fixtures: detect_transactional_fixtures,
    queue_adapter_in_tests: detect_queue_adapter,
    test_stack:             test_stack_for(gems),
    schema:                 SchemaReader.read(@root),
    factories:              FactoryRegistry.read(@root),
    notes:                  @notes
  )
end