Sha256: 1fdf9492258fa936ce99bebecfbd06bde4a249ba6e57a0d618363c875f1aa4e1

Contents?: true

Size: 926 Bytes

Versions: 5

Compression:

Stored size: 926 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) if mod
      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

5 entries across 5 versions & 1 rubygems

Version Path
rails_best_practices-1.20.0 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.19.5 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.19.4 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.19.3 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.19.2 lib/rails_best_practices/core/modules.rb