Module: Card::Env
- Extended by:
- LocationHistory, RequestAssignments, Serialization, SlotOptions
- Defined in:
- lib/card/env.rb,
lib/card/env/success.rb,
lib/card/env/location.rb,
lib/card/env/slot_options.rb,
lib/card/env/serialization.rb,
lib/card/env/location_history.rb,
lib/card/env/request_assignments.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, RequestAssignments, Serialization, SlotOptions
Classes: Success
Constant Summary
Serialization::SERIALIZABLE_ATTRIBUTES
Class Method Summary
collapse
discard_locations_for, interrupted_action, location_history, previous_location, save_interrupted_action, save_location, save_location?, url_key_for_location
slot_opts
serialize, with
Class Method Details
.[](key) ⇒ Object
28
29
30
|
# File 'lib/card/env.rb', line 28
def [] key
@env[key.to_sym]
end
|
.[]=(key, value) ⇒ Object
32
33
34
|
# File 'lib/card/env.rb', line 32
def []= key, value
@env[key.to_sym] = value
end
|
.ajax? ⇒ Boolean
68
69
70
|
# File 'lib/card/env.rb', line 68
def ajax?
self[:ajax]
end
|
.hash(hashish) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/card/env.rb', line 40
def hash hashish
case hashish
when Hash then hashish.clone
when ActionController::Parameters then hashish.to_unsafe_h
else {}
end
end
|
.html? ⇒ Boolean
72
73
74
|
# File 'lib/card/env.rb', line 72
def html?
!self[:controller] || self[:html]
end
|
.localhost? ⇒ Boolean
64
65
66
|
# File 'lib/card/env.rb', line 64
def localhost?
self[:host]&.match?(/^localhost/)
end
|
.params ⇒ Object
36
37
38
|
# File 'lib/card/env.rb', line 36
def params
self[:params] ||= {}
end
|
.reset(args = {}) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/card/env.rb', line 13
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
|
.reset_session ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/card/env.rb', line 52
def reset_session
if session.is_a? Hash
self[:session] = {}
else
self[:controller]&.reset_session
end
end
|
.session ⇒ Object
48
49
50
|
# File 'lib/card/env.rb', line 48
def session
self[:session] ||= {}
end
|
.success(cardname = nil) ⇒ Object
60
61
62
|
# File 'lib/card/env.rb', line 60
def success cardname=nil
self[:success] ||= Env::Success.new(cardname, params[:success])
end
|