Sha256: aff3b6b8a82549597ffb3280202248b365f7f8710aa0f62a8740b56c0e07c705

Contents?: true

Size: 850 Bytes

Versions: 15

Compression:

Stored size: 850 Bytes

Contents

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

      attr_accessor :session

      def match_field
        "(?:\\w+: (?:#{match_model}|#{match_value}))"
      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    
      
      def parse_hash(hash)
        hash.inject({}) do |parsed, (key, val)|
          if session && val =~ /^#{capture_model}$/
            parsed.merge(key => session.model($1))
          else
            parsed.merge(key => val)
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
pickle-0.5.0 lib/pickle/session/parser.rb
pickle-0.4.11 lib/pickle/session/parser.rb
pickle-0.4.10 lib/pickle/session/parser.rb
pickle-0.4.9 lib/pickle/session/parser.rb
pickle-0.4.8 lib/pickle/session/parser.rb
pickle-0.4.7 lib/pickle/session/parser.rb
pickle-0.4.6 lib/pickle/session/parser.rb
pickle-0.4.5 lib/pickle/session/parser.rb
pickle-0.4.4 lib/pickle/session/parser.rb
judit-pickle-0.4.2 lib/pickle/session/parser.rb
pickle-0.4.3 lib/pickle/session/parser.rb
pickle-has_many_support-0.4.2 lib/pickle/session/parser.rb
pickle-0.4.2 lib/pickle/session/parser.rb
pickle-0.4.1 lib/pickle/session/parser.rb
pickle-0.4.0 lib/pickle/session/parser.rb