Class: RailsAppGenerator::Addon

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Actions, Rails::Generators::AppName, Thor::Actions
Defined in:
lib/rails_app_generator/addon.rb

Overview

Base class for all add-ons

Direct Known Subclasses

RailsAppGenerator::AddOns::ActsAsList, RailsAppGenerator::AddOns::Administrate, RailsAppGenerator::AddOns::Annotate, RailsAppGenerator::AddOns::Avo, RailsAppGenerator::AddOns::Bcrypt, RailsAppGenerator::AddOns::Brakeman, RailsAppGenerator::AddOns::Browser, RailsAppGenerator::AddOns::BundlerAudit, RailsAppGenerator::AddOns::Chartkick, RailsAppGenerator::AddOns::ContinuousIntegration, RailsAppGenerator::AddOns::Devise, RailsAppGenerator::AddOns::DeviseMasquerade, RailsAppGenerator::AddOns::Docker, RailsAppGenerator::AddOns::DockerCompose, RailsAppGenerator::AddOns::Dotenv, RailsAppGenerator::AddOns::FactoryBot, RailsAppGenerator::AddOns::FactoryBotRails, RailsAppGenerator::AddOns::Faker, RailsAppGenerator::AddOns::Foreman, RailsAppGenerator::AddOns::FriendlyId, RailsAppGenerator::AddOns::Generators, RailsAppGenerator::AddOns::Groupdate, RailsAppGenerator::AddOns::Hexapdf, RailsAppGenerator::AddOns::HighVoltage, RailsAppGenerator::AddOns::Honeybadger, RailsAppGenerator::AddOns::Httparty, RailsAppGenerator::AddOns::ImageProcessing, RailsAppGenerator::AddOns::InlineSvg, RailsAppGenerator::AddOns::Irbrc, RailsAppGenerator::AddOns::Kaminari, RailsAppGenerator::AddOns::Lograge, RailsAppGenerator::AddOns::MiniMagick, RailsAppGenerator::AddOns::MinimalCss, RailsAppGenerator::AddOns::MotorAdmin, RailsAppGenerator::AddOns::PhonyRails, RailsAppGenerator::AddOns::Pretender, RailsAppGenerator::AddOns::PublicSuffix, RailsAppGenerator::AddOns::Pundit, RailsAppGenerator::AddOns::RailsHtmlSanitizer, RailsAppGenerator::AddOns::Ransack, RailsAppGenerator::AddOns::Redcarpet, RailsAppGenerator::AddOns::Rolify, RailsAppGenerator::AddOns::Rspec, RailsAppGenerator::AddOns::Rubocop, RailsAppGenerator::AddOns::Scaffold, RailsAppGenerator::AddOns::Scenic, RailsAppGenerator::AddOns::Services, RailsAppGenerator::AddOns::Sidekiq, RailsAppGenerator::AddOns::Stimulus, RailsAppGenerator::AddOns::StimulusComponents, RailsAppGenerator::AddOns::Tailwind, RailsAppGenerator::AddOns::TwilioRuby, RailsAppGenerator::AddOns::ViewComponent, RailsAppGenerator::AddOns::Views

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Addon

Returns a new instance of Addon.



14
15
16
17
18
19
# File 'lib/rails_app_generator/addon.rb', line 14

def initialize(context)
  super
  @context = context
  @dependencies = self.class.dependencies || []
  @gem_entries = self.class.gem_entries || []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/rails_app_generator/addon.rb', line 10

def context
  @context
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



12
13
14
# File 'lib/rails_app_generator/addon.rb', line 12

def dependencies
  @dependencies
end

#gem_entriesObject (readonly)

Returns the value of attribute gem_entries.



11
12
13
# File 'lib/rails_app_generator/addon.rb', line 11

def gem_entries
  @gem_entries
end

Class Method Details

.addon_nameObject



107
108
109
# File 'lib/rails_app_generator/addon.rb', line 107

def addon_name
  name.demodulize.underscore.to_sym
end

.dependenciesObject



111
112
113
# File 'lib/rails_app_generator/addon.rb', line 111

def dependencies
  @dependencies ||= []
end

.depends_on(*addon) ⇒ Object



119
120
121
# File 'lib/rails_app_generator/addon.rb', line 119

def depends_on(*addon)
  @dependencies = addon.map(&:to_sym)
end

.gemObject



141
142
143
# File 'lib/rails_app_generator/addon.rb', line 141

def gem
  Rails::Generators::AppBase::GemfileEntry
end

.gem_entriesObject



115
116
117
# File 'lib/rails_app_generator/addon.rb', line 115

def gem_entries
  @gem_entries ||= []
end

.required_gem(gem_entry) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/rails_app_generator/addon.rb', line 123

def required_gem(gem_entry)
  existing_gem = gem_entries.find { |gem| gem.name == gem_entry.name }

  if existing_gem
    return if Gem::Version.new(gem_entry.version) < Gem::Version.new(existing_gem.version)

    existing_gem.version = gem_entry.version
    existing_gem.comment = gem_entry.comment
    return
  end

  gem_entries << gem_entry
end

.reset_gem_entriesObject



137
138
139
# File 'lib/rails_app_generator/addon.rb', line 137

def reset_gem_entries
  @gem_entries = []
end

Instance Method Details

#applyObject



21
# File 'lib/rails_app_generator/addon.rb', line 21

def apply; end