Sha256: f42aae1606032ae52fb04a6cc1fe56b35dd6ae4eb17a584655246994e2980661

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

module PageEz
  module Visitors
    class MacroPluralizationVisitor
      def initialize
        reset
      end

      def begin_block_evaluation
        @depth_visitor.begin_block_evaluation
      end

      def end_block_evaluation
        @depth_visitor.end_block_evaluation
      end

      def define_method(name)
        @depth_visitor.define_method(name)
      end

      def inherit_from(subclass)
        @depth_visitor.inherit_from(subclass)
      end

      def track_method_added(name, construction_strategy)
        @depth_visitor.track_method_added(name, construction_strategy)
      end

      def track_method_undefined(name)
        @depth_visitor.track_method_undefined(name)
      end

      def track_method_renamed(from, to)
        @depth_visitor.track_method_renamed(from, to)
      end

      def track_method_delegated(name)
        @depth_visitor.track_method_delegated(name)
      end

      def process_macro(macro, name, construction_strategy)
        @depth_visitor.process_macro(macro, name, construction_strategy)
        rendered = "#{macro} :#{name}, \"#{construction_strategy.selector}\""

        message = case [macro, Pluralization.new(name).singular? ? :singular : :plural]
        in [:has_one, :plural]
          "consider singularizing :#{name} in #{rendered}"
        in [:has_many, :singular]
          "consider pluralizing :#{name} in #{rendered}"
        in [:has_many_ordered, :singular]
          "consider pluralizing :#{name} in #{rendered}"
        in _
        end

        if message
          message = "#{"  " * @depth_visitor.depth}#{message}"
          case PageEz.configuration.on_pluralization_mismatch
          when :warn
            PageEz.configuration.logger.warn(message)
          when :raise
            raise PluralizationMismatchError, message
          end
        end
      end

      def reset
        @depth_visitor = DepthVisitor.new
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
page_ez-0.2.0 lib/page_ez/visitors/macro_pluralization_visitor.rb
page_ez-0.1.0 lib/page_ez/visitors/macro_pluralization_visitor.rb