Sha256: 11cd122ed336cb2eea357b3e47204c22880911175797265f645187c881975ec8

Contents?: true

Size: 840 Bytes

Versions: 2

Compression:

Stored size: 840 Bytes

Contents

require 'action_view'
require 'action_controller'
require 'gon/helpers'

module Gon
  def self.all_variables
    @request_env[:gon]
  end

  def self.clear
    @request_env[:gon] = {}
  end

  def self.request_env=(request_env)
    @request_env = request_env
  end

  def self.request_env
    if defined?(@request_env)
      return @request_env
    end
  end

  def self.method_missing(m, *args, &block)
    @request_env[:gon] ||= {}

    if ( m.to_s =~ /=$/ )
      if self.public_methods.include? m[0..-2].to_sym
        raise "You can't use Gon public methods for storing data"
      end
      set_variable(m.to_s.delete('='), args[0])
    else
      get_variable(m.to_s)
    end
  end

  def self.get_variable(name)
    @request_env[:gon][name]
  end

  def self.set_variable(name, value)
    @request_env[:gon][name] = value
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gon-1.1.2 lib/gon.rb
gon-1.1.1 lib/gon.rb