Sha256: 58f64ac700a67c16039359fc0e5da0dd28ea30fd0d2ef29b36e5bedd0e1ec32f

Contents?: true

Size: 584 Bytes

Versions: 3

Compression:

Stored size: 584 Bytes

Contents

module Pickle
  class Parser
    # add ability to parse model names as fields, using a session
    module WithSession
      def self.included(parser_class)
        parser_class.alias_method_chain :parse_field, :model
      end

      attr_accessor :session

      def match_field
        "(?:\\w+: (?:#{match_model}|\"#{match_quoted}\"))"
      end

      def parse_field_with_model(field)
        if session && field =~ /^(\w+): #{capture_model}$/
          {$1 => session.model($2)}
        else
          parse_field_without_model(field)
        end
      end    
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ianwhite-pickle-0.1.2 lib/pickle/parser/with_session.rb
ianwhite-pickle-0.1.3 lib/pickle/parser/with_session.rb
ianwhite-pickle-0.1.4 lib/pickle/parser/with_session.rb