Module: PlutoniumGenerators::Generator
- Included in:
- ModelGeneratorBase, Pu::Core::AssetsGenerator, Pu::Core::InstallGenerator, Pu::Core::RubyGenerator, Pu::Core::TypespecGenerator, Pu::Core::UpdateGenerator, Pu::Docker::InstallGenerator, Pu::Eject::LayoutGenerator, Pu::Eject::ShellGenerator, Pu::Extra::ColorizedLoggerGenerator, Pu::Field::InputGenerator, Pu::Field::RendererGenerator, Pu::Gem::ActiveShrineGenerator, Pu::Gem::AnnotatedGenerator, Pu::Gem::DotenvGenerator, Pu::Gem::LetterOpenerGenerator, Pu::Gem::RedisGenerator, Pu::Gem::StandardGenerator, Pu::Gem::StateMachinesGenerator, Pu::Invites::InstallGenerator, Pu::Invites::InvitableGenerator, Pu::Lite::LitestreamGenerator, Pu::Lite::RailsPulseGenerator, Pu::Lite::SetupGenerator, Pu::Lite::SolidCableGenerator, Pu::Lite::SolidCacheGenerator, Pu::Lite::SolidErrorsGenerator, Pu::Lite::SolidQueueGenerator, Pu::Pkg::PackageGenerator, Pu::Pkg::PortalGenerator, Pu::Profile::ConnGenerator, Pu::Profile::InstallGenerator, Pu::Profile::SetupGenerator, Pu::Res::ConnGenerator, Pu::Res::ScaffoldGenerator, Pu::Saas::ApiClientGenerator, Pu::Saas::EntityGenerator, Pu::Saas::MembershipGenerator, Pu::Saas::PortalGenerator, Pu::Saas::SetupGenerator, Pu::Saas::WelcomeGenerator, Pu::Service::PostgresGenerator, Pu::Service::SidekiqGenerator, Pu::Skills::SyncGenerator, Pu::Test::InstallGenerator, Pu::Test::ScaffoldGenerator
- Defined in:
- lib/generators/pu/lib/plutonium_generators/generator.rb
Class Method Summary collapse
-
.derive_association_name(from_model, to_model) ⇒ Object
Derives the association name for a reference, stripping shared namespace.
-
.find_shared_namespace(model1, model2, separator: "/") ⇒ Object
Finds the shared namespace prefix between two model names.
- .included(base) ⇒ Object
Methods included from Concerns::Logger
#debug, #error, #exception, #info, #success, #warn
Methods included from Concerns::Config
Class Method Details
.derive_association_name(from_model, to_model) ⇒ Object
Derives the association name for a reference, stripping shared namespace. e.g., derive_association_name(“Competition::TeamUser”, “Competition::Team”) => “team”
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/pu/lib/plutonium_generators/generator.rb', line 31 def self.derive_association_name(from_model, to_model) to_parts = to_model.underscore.split("/") if (shared = find_shared_namespace(from_model, to_model)) shared_parts = shared.split("/") to_parts = to_parts.drop(shared_parts.length) end to_parts.join("_") end |
.find_shared_namespace(model1, model2, separator: "/") ⇒ Object
Finds the shared namespace prefix between two model names. Used to derive association names when models share a namespace. e.g., find_shared_namespace(“Competition::TeamUser”, “Competition::Team”) => “competition”
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generators/pu/lib/plutonium_generators/generator.rb', line 16 def self.find_shared_namespace(model1, model2, separator: "/") parts1 = model1.underscore.split(separator) parts2 = model2.underscore.split(separator) shared = [] [parts1.length, parts2.length].min.times do |i| break unless parts1[i] == parts2[i] shared << parts1[i] end shared.empty? ? nil : shared.join(separator) end |
.included(base) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/generators/pu/lib/plutonium_generators/generator.rb', line 42 def self.included(base) base.send :class_option, :interactive, type: :boolean, desc: "Show prompts. Default: true" base.send :class_option, :bundle, type: :boolean, desc: "Run bundle after setup. Default: true" base.send :class_option, :lint, type: :boolean, desc: "Run linter after generation. Default: false" base.include Concerns::PackageSelector end |