Sha256: 9791c7fd7514e0f74b3f93448168dbd62bd0e10f3b0c8924c5bcb87785dfd44a

Contents?: true

Size: 913 Bytes

Versions: 5

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

5 entries across 5 versions & 1 rubygems

Version Path
rails_best_practices-1.19.0 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.18.1 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.18.0 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.17.0 lib/rails_best_practices/core/modules.rb
rails_best_practices-1.16.0 lib/rails_best_practices/core/modules.rb