Class: Card::Env::Success

Inherits:
Object
  • Object
show all
Includes:
Location
Defined in:
lib/card/env/success.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Location

#card_path, #card_url, #page_path

Constructor Details

#initialize(name_context = nil, success_params = nil) ⇒ Success

Returns a new instance of Success.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/card/env/success.rb', line 8

def initialize name_context=nil, success_params=nil
  @name_context = name_context
  @new_args = {}
  @params = OpenStruct.new
  case success_params
  when Hash
    apply(success_params)
  when nil then  self.name = "_self"
  else;  self.target = success_params
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



132
133
134
135
136
137
138
139
140
141
# File 'lib/card/env/success.rb', line 132

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

Returns the value of attribute card.



6
7
8
# File 'lib/card/env/success.rb', line 6

def card
  @card
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/card/env/success.rb', line 6

def id
  @id
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/card/env/success.rb', line 6

def name
  @name
end

#name_contextObject

Returns the value of attribute name_context.



6
7
8
# File 'lib/card/env/success.rb', line 6

def name_context
  @name_context
end

#paramsObject

Returns the value of attribute params.



6
7
8
# File 'lib/card/env/success.rb', line 6

def params
  @params
end

#redirectObject

Returns the value of attribute redirect.



6
7
8
# File 'lib/card/env/success.rb', line 6

def redirect
  @redirect
end

Instance Method Details

#<<(value) ⇒ Object



20
21
22
23
24
25
# File 'lib/card/env/success.rb', line 20

def << value
  case value
  when Hash then apply value
  else; self.target = value
  end
end

#[](key) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/card/env/success.rb', line 105

def [] key
  if respond_to? key.to_sym
    send key.to_sym
  elsif key.to_sym == :soft_redirect
    @redirect == :soft
  else
    @params.send key.to_sym
  end
end

#[]=(key, value) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/card/env/success.rb', line 95

def []= key, value
  if respond_to? "#{key}="
    send "#{key}=", value
  elsif key.to_sym == :soft_redirect
    @redirect = :soft
  else
    @params.send "#{key}=", value
  end
end

#apply(args) ⇒ Object



75
76
77
78
79
# File 'lib/card/env/success.rb', line 75

def apply args
  args.each_pair do |key, value|
    self[key] = value
  end
end

#content=(content) ⇒ Object



53
54
55
# File 'lib/card/env/success.rb', line 53

def content= content
  @new_args[:content] = content
end

#hard_redirect?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/card/env/success.rb', line 27

def hard_redirect?
  @redirect == true
end

#mark=(value) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/card/env/success.rb', line 36

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

#process_target(value) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/card/env/success.rb', line 62

def process_target value
  case value
  when ""                     then ""
  when "*previous", :previous then :previous
  when /^(http|\/)/           then value
  when /^TEXT:\s*(.+)/        then  Regexp.last_match(1)
  when /^REDIRECT:\s*(.+)/
    @redirect = true
    process_target Regexp.last_match(1)
  else self.mark = value
  end
end

#raw_paramsObject



119
120
121
# File 'lib/card/env/success.rb', line 119

def raw_params
  @params
end

#sessionObject



143
144
145
# File 'lib/card/env/success.rb', line 143

def session
  Card::Env.session
end

#soft_redirect?Boolean

reset card object and override params with success params

Returns:

  • (Boolean)


32
33
34
# File 'lib/card/env/success.rb', line 32

def soft_redirect?
  @redirect == :soft
end

#target(name_context = @name_context) ⇒ Object



91
92
93
# File 'lib/card/env/success.rb', line 91

def target name_context=@name_context
  card(name_context) || (@target == :previous ? Card::Env.previous_location : @target) || Card.fetch(name_context)
end

#target=(value) ⇒ Object



57
58
59
60
# File 'lib/card/env/success.rb', line 57

def target= value
  @id = @name = @card = nil
  @target = process_target value
end

#to_url(name_context = @name_context) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/card/env/success.rb', line 123

def to_url name_context=@name_context
  case (target = target(name_context))
  when Card
    page_path target.cardname, params
  else
    target
  end
end

#type=(type) ⇒ Object



49
50
51
# File 'lib/card/env/success.rb', line 49

def type= type
  @new_args[:type] = type
end