Class: Card::Env::Success

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

Overview

Success objects

Defined Under Namespace

Modules: Target

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Target

#card, #content=, #id=, #mark=, #target, #target=, #type=, #type_id=

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.



12
13
14
15
16
17
# File 'card/lib/card/env/success.rb', line 12

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 (private)



81
82
83
84
85
# File 'card/lib/card/env/success.rb', line 81

def method_missing method, *args
  return super unless (m = method.match(/^(\w+(=)?)/))

  infer_bracket m[1].to_sym, m[2], args[0]
end

Instance Attribute Details

#card=(value) ⇒ Object (writeonly)

Sets the attribute card

Parameters:

  • value

    the value to set the attribute card to.



9
10
11
# File 'card/lib/card/env/success.rb', line 9

def card=(value)
  @card = value
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'card/lib/card/env/success.rb', line 10

def id
  @id
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'card/lib/card/env/success.rb', line 8

def name
  @name
end

#name_contextObject

Returns the value of attribute name_context.



8
9
10
# File 'card/lib/card/env/success.rb', line 8

def name_context
  @name_context
end

#paramsObject



67
68
69
# File 'card/lib/card/env/success.rb', line 67

def params
  @params.marshal_dump
end

#redirectObject



37
38
39
# File 'card/lib/card/env/success.rb', line 37

def redirect
  @redirect.present? ? @redirect : false
end

#reloadObject

Returns the value of attribute reload.



8
9
10
# File 'card/lib/card/env/success.rb', line 8

def reload
  @reload
end

Instance Method Details

#<<(value) ⇒ Object



29
30
31
32
33
34
35
# File 'card/lib/card/env/success.rb', line 29

def << value
  if value.is_a? Hash
    apply value
  else
    self.mark = value
  end
end

#[](key) ⇒ Object



53
54
55
56
57
58
59
# File 'card/lib/card/env/success.rb', line 53

def [] key
  if respond_to? key.to_sym
    send key.to_sym
  else
    @params.send key.to_sym
  end
end

#[]=(key, value) ⇒ Object



45
46
47
48
49
50
51
# File 'card/lib/card/env/success.rb', line 45

def []= key, value
  if respond_to? "#{key}="
    send "#{key}=", value
  else
    @params.send "#{key}=", value
  end
end

#flash(message = nil) ⇒ Object



61
62
63
64
65
# File 'card/lib/card/env/success.rb', line 61

def flash message=nil
  @params[:flash] ||= []
  @params[:flash] << message if message
  @params[:flash]
end

#in_context(name_context) ⇒ Object



24
25
26
27
# File 'card/lib/card/env/success.rb', line 24

def in_context name_context
  self.name_context = name_context
  self
end

#reload?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'card/lib/card/env/success.rb', line 41

def reload?
  @reload.to_s == "true"
end

#sessionObject



71
72
73
# File 'card/lib/card/env/success.rb', line 71

def session
  Card::Env.session
end

#to_url(name_context = @name_context) ⇒ Object



19
20
21
22
# File 'card/lib/card/env/success.rb', line 19

def to_url name_context=@name_context
  target = target name_context
  target.is_a?(Card) ? target.format.path(params) : target
end