Sha256: 1520085ded95b205b93abb5e3bc48bab043cc5b7d6b60642f698635d66555fc5

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

# encoding: utf-8
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

1 entries across 1 versions & 1 rubygems

Version Path
rails_best_practices-1.19.1 lib/rails_best_practices/core/modules.rb