Sha256: 438c8dc88c4b0b9662fb11a0b343a33f21db2a613b13fc1d788395bcd39893c9

Contents?: true

Size: 990 Bytes

Versions: 1

Compression:

Stored size: 990 Bytes

Contents

require "method_source"

module Kanal
  module Core
    module Helpers
      # Class helps with parsing router procs for
      # helping forming handy DSL without commas
      class RouterProcParser
        def get_conditions_method_names_from_block(&block)
          source = block.source.to_s

          method_names = []

          lines = source.split "\n"

          lines.each do |l|
            names = get_method_names_from_line l

            method_names.concat names
          end

          method_names.uniq
        end

        def get_method_names_from_line(line)
          method_names = []

          line = line.lstrip

          return method_names unless line.start_with? "on"

          words = line.split

          condition_pack = words[1]
          condition = words[2]

          method_names.append condition_pack
          method_names.append condition

          method_names
        end

        private :get_method_names_from_line
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kanal-0.3.0 lib/kanal/core/helpers/router_proc_parser.rb