Sha256: 61eb18c07670a4c92c88c61ace7860c5ed79c74fcee02ca56f818a98f9c76020
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
module Gon module Sinatra class Store attr_accessor :request def initialize(variables) @env = variables end def all_variables @env end def clear @env.clear end def method_missing(method, *args, &block) if ( method.to_s =~ /=$/ ) if public_methods.include? method.to_s[0..-2].to_sym raise "You can't use Gon public methods for storing data" end set_variable(method.to_s.delete('='), args[0]) else get_variable(method.to_s) end end def get_variable(name) @env && @env[name] end alias :get :get_variable def set_variable(name, value) @env[name] = value end alias :set :set_variable def rabl(view_path, options = {}) unless defined?(::Rabl) raise Exception.new("You must require rabl and register Gon::Sinatra::Rabl to use rabl") end unless options[:instance] raise ArgumentError.new("You should pass :instance in options: :instance => self") end rabl_data = Gon::Sinatra::Rabl.parse_rabl(view_path, options[:instance]) if options[:as] set_variable(options[:as].to_s, rabl_data) elsif rabl_data.is_a? Hash rabl_data.each do |key, value| set_variable(key, value) end else set_variable('rabl', rabl_data) end end def jbuilder(view_path, options = {}) raise NoMethodError.new("Not available for sinatra") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gon-sinatra-0.1.2 | lib/gon/sinatra/store.rb |