Module: Card::Env
- Extended by:
- LocationHistory
- Defined in:
- lib/card/env.rb,
lib/card/env/success.rb,
lib/card/env/location.rb,
lib/card/env/location_history.rb
Overview
Card::Env is a module for containing the variable details of the environment
in which Card operates.
Env can differ for each request; Card.config should not.
Defined Under Namespace
Modules: Location, LocationHistory
Classes: Success
Constant Summary
collapse
- SERIALIZABLE_ATTRIBUTES =
::Set.new [
:main_name, :params, :ip, :ajax, :html, :host, :protocol, :salt
]
Class Method Summary
collapse
discard_locations_for, interrupted_action, location_history, previous_location, save_interrupted_action, save_location, save_location?, url_key_for_location
Class Method Details
.[](key) ⇒ Object
31
32
33
|
# File 'lib/card/env.rb', line 31
def [] key
@env[key.to_sym]
end
|
.[]=(key, value) ⇒ Object
35
36
37
|
# File 'lib/card/env.rb', line 35
def []= key, value
@env[key.to_sym] = value
end
|
.ajax? ⇒ Boolean
55
56
57
|
# File 'lib/card/env.rb', line 55
def ajax?
self[:ajax]
end
|
.deserialize!(data) ⇒ Object
67
68
69
70
|
# File 'lib/card/env.rb', line 67
def deserialize! data
@env ||= {}
@env.update data
end
|
.html? ⇒ Boolean
59
60
61
|
# File 'lib/card/env.rb', line 59
def html?
!self[:controller] || self[:html]
end
|
.localhost? ⇒ Boolean
51
52
53
|
# File 'lib/card/env.rb', line 51
def localhost?
self[:host] && self[:host] =~ /^localhost/
end
|
.params ⇒ Object
39
40
41
|
# File 'lib/card/env.rb', line 39
def params
self[:params] ||= {}
end
|
.reset(args = {}) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/card/env.rb', line 17
def reset args={}
@env = { main_name: nil }
return self unless (c = args[:controller])
self[:controller] = c
self[:session] = c.request.session
self[:params] = c.params
self[:ip] = c.request.remote_ip
self[:ajax] = assign_ajax(c)
self[:html] = assign_html(c)
self[:host] = assign_host(c)
self[:protocol] = assign_protocol(c)
self
end
|
.serialize ⇒ Object
63
64
65
|
# File 'lib/card/env.rb', line 63
def serialize
@env.select { |k, _v| SERIALIZABLE_ATTRIBUTES.include?(k) }
end
|
.session ⇒ Object
43
44
45
|
# File 'lib/card/env.rb', line 43
def session
self[:session] ||= {}
end
|
.success(cardname = nil) ⇒ Object
47
48
49
|
# File 'lib/card/env.rb', line 47
def success cardname=nil
self[:success] ||= Env::Success.new(cardname, params[:success])
end
|