Module: Rack::Less::Options::InstanceMethods

Defined in:
lib/rack/less/options.rb

Instance Method Summary collapse

Instance Method Details

#option_name(key) ⇒ Object

Rack::Less uses the Rack Environment to store option values. All options are stored in the Rack Environment as “<RACK_ENV_PREFIX>.<option>”, where <option> is the option name.



53
54
55
# File 'lib/rack/less/options.rb', line 53

def option_name(key)
  self.class.option_name(key)
end

#options(key = nil) ⇒ Object

The underlying options Hash. During initialization (or outside of a request), this is a default values Hash. During a request, this is the Rack environment Hash. The default values Hash is merged in underneath the Rack environment before each request is processed.

> if a key is passed, the option value for the key is returned



62
63
64
65
66
67
68
# File 'lib/rack/less/options.rb', line 62

def options(key=nil)
  if key
    (@env || @default_options)[option_name(key)]
  else
    @env || @default_options
  end
end

#options=(hash = {}) ⇒ Object

Set multiple options at once.



71
72
73
# File 'lib/rack/less/options.rb', line 71

def options=(hash={})
  hash.each { |key,value| write_option(key, value) }
end

#set(option, value = nil) ⇒ Object

Set an option. When option is a Symbol, it is set in the Rack Environment as “rack-cache.option”. When option is a String, it exactly as specified. The option argument may also be a Hash in which case each key/value pair is merged into the environment as if the #set method were called on each.



80
81
82
83
84
85
86
# File 'lib/rack/less/options.rb', line 80

def set(option, value=nil)
  if value.nil?
    self.options = option.to_hash
  else
    write_option option, value
  end
end