Sha256: cc94243b139d4da718b28752c0833154c4d627e411a9f186af9b5b90e8165b2e

Contents?: true

Size: 920 Bytes

Versions: 7

Compression:

Stored size: 920 Bytes

Contents

# frozen_string_literal: true

module RailsBestPractices
  module Core
    # Module container
    class Modules < Array
      # add module descendant.
      #
      # @param [String] module name
      # @param [String] descendant name
      def add_module_descendant(module_name, descendant)
        mod = find { |mod| mod.to_s == module_name }
        mod&.add_descendant(descendant)
      end
    end

    # Module info include module name and module spaces.
    class Mod
      attr_reader :descendants

      def initialize(module_name, modules)
        @module_name = module_name
        @modules = modules
        @descendants = []
      end

      def add_descendant(descendant)
        @descendants << descendant
      end

      def to_s
        if @modules.empty?
          @module_name
        else
          @modules.map { |modu| "#{modu}::" }.join('') + @module_name
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_best_practices-1.23.2 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.23.1 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.23.0 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.22.1 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.22.0 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.21.0 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.20.1 lib/rails_best_practices/core/modules.rb