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
64
65
66
|
# File 'lib/card/env.rb', line 64
def ajax?
self[:ajax]
end
|
.html? ⇒ Boolean
68
69
70
|
# File 'lib/card/env.rb', line 68
def html?
!self[:controller] || self[:html]
end
|
.localhost? ⇒ Boolean
60
61
62
|
# File 'lib/card/env.rb', line 60
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
72
73
74
|
# File 'lib/card/env.rb', line 72
def serialize
@env.select { |k, _v| SERIALIZABLE_ATTRIBUTES.include?(k) }
end
|
.session ⇒ Object
52
53
54
|
# File 'lib/card/env.rb', line 52
def session
self[:session] ||= {}
end
|
.slot_opts ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/card/env.rb', line 43
def slot_opts
self[:slot_opts] ||= begin
opts = params[:slot] || {}
opts = opts.to_unsafe_h if opts.is_a? ActionController::Parameters
opts.deep_symbolize_keys
end
end
|
.success(cardname = nil) ⇒ Object
56
57
58
|
# File 'lib/card/env.rb', line 56
def success cardname=nil
self[:success] ||= Env::Success.new(cardname, params[:success])
end
|
.with(serialized_env) ⇒ Object
77
78
79
80
81
82
83
84
|
# File 'lib/card/env.rb', line 77
def with serialized_env
tmp_env = serialize if @env
@env ||= {}
@env.update serialized_env
yield
ensure
@env.update tmp_env if tmp_env
end
|