Class: Card::Env::Success
- Inherits:
-
Object
- Object
- Card::Env::Success
show all
- Includes:
- Location
- Defined in:
- lib/card/env/success.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Location
#card_path, #card_url, #cardname_from_url, #protocol_and_host
Constructor Details
#initialize(name_context = nil, success_args = nil) ⇒ Success
Returns a new instance of Success.
11
12
13
14
15
16
|
# File 'lib/card/env/success.rb', line 11
def initialize name_context=nil, success_args=nil
@name_context = name_context
@new_args = {}
@params = OpenStruct.new
self << normalize_success_args(success_args)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/card/env/success.rb', line 155
def method_missing method, *args
case method
when /^(\w+)=$/
self[Regexp.last_match(1).to_sym] = args[0]
when /^(\w+)$/
self[Regexp.last_match(1).to_sym]
else
super
end
end
|
Instance Attribute Details
#card(name_context = @name_context) ⇒ Object
100
101
102
103
104
105
106
107
108
|
# File 'lib/card/env/success.rb', line 100
def card name_context=@name_context
if @card
@card
elsif @id
Card.find @id
elsif @name
Card.fetch @name.to_name.absolute(name_context), new: @new_args
end
end
|
#id ⇒ Object
Returns the value of attribute id.
9
10
11
|
# File 'lib/card/env/success.rb', line 9
def id
@id
end
|
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/card/env/success.rb', line 7
def name
@name
end
|
#name_context ⇒ Object
Returns the value of attribute name_context.
7
8
9
|
# File 'lib/card/env/success.rb', line 7
def name_context
@name_context
end
|
#params ⇒ Object
138
139
140
|
# File 'lib/card/env/success.rb', line 138
def params
@params.marshal_dump
end
|
#redirect ⇒ Object
Returns the value of attribute redirect.
7
8
9
|
# File 'lib/card/env/success.rb', line 7
def redirect
@redirect
end
|
#reload ⇒ Object
Returns the value of attribute reload.
7
8
9
|
# File 'lib/card/env/success.rb', line 7
def reload
@reload
end
|
Instance Method Details
#<<(value) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/card/env/success.rb', line 35
def << value
if value.is_a? Hash
apply value
else
self.target = value
end
end
|
#[](key) ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/card/env/success.rb', line 124
def [] key
if respond_to? key.to_sym
send key.to_sym
else
@params.send key.to_sym
end
end
|
#[]=(key, value) ⇒ Object
116
117
118
119
120
121
122
|
# File 'lib/card/env/success.rb', line 116
def []= key, value
if respond_to? "#{key}="
send "#{key}=", value
else
@params.send "#{key}=", value
end
end
|
#apply(hash) ⇒ Object
94
95
96
97
98
|
# File 'lib/card/env/success.rb', line 94
def apply hash
hash.each_pair do |key, value|
self[key] = value
end
end
|
#content=(content) ⇒ Object
73
74
75
|
# File 'lib/card/env/success.rb', line 73
def content= content
@new_args[:content] = content
end
|
#flash(message = nil) ⇒ Object
132
133
134
135
136
|
# File 'lib/card/env/success.rb', line 132
def flash message=nil
@params[:flash] ||= []
@params[:flash] << message if message
@params[:flash]
end
|
#in_context(name_context) ⇒ Object
18
19
20
21
|
# File 'lib/card/env/success.rb', line 18
def in_context name_context
self.name_context = name_context
self
end
|
#mark=(value) ⇒ Object
TODO: refactor to use cardish
48
49
50
51
52
53
54
55
56
|
# File 'lib/card/env/success.rb', line 48
def mark= value
case value
when Integer then @id = value
when String then @name = value
when Card then @card = value
else
self.target = value
end
end
|
#normalize_success_args(success_args) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/card/env/success.rb', line 23
def normalize_success_args success_args
case success_args
when nil
self.mark = "_self"
{}
when ActionController::Parameters
success_args.to_unsafe_h
else
success_args
end
end
|
#process_target(value) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/card/env/success.rb', line 82
def process_target value
case value
when "" then ""
when "*previous", :previous then :previous
when %r{^(http|/)} then value
when /^REDIRECT:\s*(.+)/
@redirect = true
process_target Regexp.last_match(1)
else self.mark = value
end
end
|
#raw_params ⇒ Object
142
143
144
|
# File 'lib/card/env/success.rb', line 142
def raw_params
@params
end
|
#reload? ⇒ Boolean
43
44
45
|
# File 'lib/card/env/success.rb', line 43
def reload?
@reload.to_s == "true"
end
|
#session ⇒ Object
166
167
168
|
# File 'lib/card/env/success.rb', line 166
def session
Card::Env.session
end
|
#target(name_context = @name_context) ⇒ Object
110
111
112
113
114
|
# File 'lib/card/env/success.rb', line 110
def target name_context=@name_context
card(name_context) ||
(@target == :previous ? Card::Env.previous_location : @target) ||
Card.fetch(name_context)
end
|
#target=(value) ⇒ Object
77
78
79
80
|
# File 'lib/card/env/success.rb', line 77
def target= value
@id = @name = @card = nil
@target = process_target value
end
|
#to_url(name_context = @name_context) ⇒ Object
146
147
148
149
150
151
152
153
|
# File 'lib/card/env/success.rb', line 146
def to_url name_context=@name_context
case (target = target(name_context))
when Card
target.format.path params
else
target
end
end
|
#type=(type) ⇒ Object
65
66
67
|
# File 'lib/card/env/success.rb', line 65
def type= type
@new_args[:type] = type
end
|
#type_id=(type_id) ⇒ Object
69
70
71
|
# File 'lib/card/env/success.rb', line 69
def type_id= type_id
@new_args[:type_id] = type_id.to_i
end
|