Sha256: 8e6c9b8e8d49ef19329996ff16b058d983958dfbddf67c7bbceae6eae586fc59

Contents?: true

Size: 969 Bytes

Versions: 7

Compression:

Stored size: 969 Bytes

Contents

# frozen_string_literal: true

require "cable_ready/installer"

if application_record_path.exist?
  lines = application_record_path.readlines

  if !lines.index { |line| line =~ /^\s*include CableReady::Updatable/ }
    proceed = if options.key? "updatable"
      options["updatable"]
    else
      !no?("✨ Include CableReady::Updatable in Active Record model classes? (Y/n)")
    end

    unless proceed
      complete_step :updatable

      puts "⏩ Skipping."
      return
    end

    index = lines.index { |line| line.include?("class ApplicationRecord < ActiveRecord::Base") }
    lines.insert index + 1, "  include CableReady::Updatable\n"
    application_record_path.write lines.join

    say "✅ included CableReady::Updatable in ApplicationRecord"
  else
    say "⏩ CableReady::Updatable has already been included in Active Record model classes. Skipping."
  end
else
  say "⏩ ApplicationRecord doesn't exist. Skipping."
end

complete_step :updatable

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cable_ready-5.0.3 lib/install/updatable.rb
cable_ready-5.0.2 lib/install/updatable.rb
cable_ready-5.0.1 lib/install/updatable.rb
cable_ready-5.0.0 lib/install/updatable.rb
cable_ready-5.0.0.rc2 lib/install/updatable.rb
cable_ready-5.0.0.rc1 lib/install/updatable.rb
cable_ready-5.0.0.pre10 lib/install/updatable.rb