Sha256: 90591f3b42daea18bb423d503fe0ece8ebc6262c8ddd61b58e7c681e987e8c1c

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require "English"

module Foobara
  module Generators
    module DomainGenerator
      class DomainConfig < Foobara::Model
        attributes do
          name :string, :required
          description :string, :allow_nil
          organization_name :string, :allow_nil
          full_module_name :string
        end

        attr_accessor :module_path

        def initialize(attributes = nil, options = {})
          full_module_name = attributes[:full_module_name]
          module_path = full_module_name&.split("::")
          name = attributes[:name]
          description = attributes[:description]
          organization_name = attributes[:organization_name]

          if organization_name.nil? && full_module_name.nil?
            full_module_name = name
            module_path = full_module_name.split("::")

            *organization_parts, name = module_path

            unless organization_parts.empty?
              organization_name = organization_parts.join("::")
            end
          end

          full_module_name ||= [*organization_name, *name].compact.join("::")

          super(
            {
              name:,
              description:,
              organization_name:,
              full_module_name:
            },
            options
          )

          self.module_path = module_path
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foobara-domain-generator-0.0.2 src/domain_config.rb
foobara-domain-generator-0.0.1 src/domain_config.rb