Module: Eve::Trust::ControllerHelpers

Defined in:
lib/eve/trust/controller_helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/eve/trust/controller_helpers.rb', line 4

def self.included(base)
  base.instance_eval do
    hide_action :trust_message, :trust_message=, :detect_igb, :template_exists?,
                :set_igb_or_default, :default_template_exists?, :mock_methods_for_testing!,
                :igb, :igb?, :set_igb, :require_trust, :prefer_trust, :deliver_trust_message
    class_attribute :trust_message
    self.trust_message ||= "This web site is requesting your trust."

    delegate :igb?, :to => :igb
    before_filter :detect_igb

    class << self
      def requires_trust(message = trust_message)
        self.trust_message = message if message != trust_message
        before_filter :require_trust
      end
  
      def prefers_trust(message = trust_message)
        self.trust_message = message if message != trust_message
        before_filter :prefer_trust
      end
    end
  end
end

Instance Method Details

#default_template_exists?(format = request.format) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
# File 'lib/eve/trust/controller_helpers.rb', line 77

def default_template_exists?(format = request.format)
  formats = lookup_context.formats
  lookup_context.formats = [format]
  lookup_context.exists?(default_template_name, controller_path)
ensure
  lookup_context.formats = formats
end

#default_template_nameObject



70
71
72
73
74
# File 'lib/eve/trust/controller_helpers.rb', line 70

def default_template_name
  # FIXME: I didn't check how Rails3 actually decides which template to render --
  # we should really follow the same rules so we don't break anything unintentionally.
  action_name
end

#deliver_trust_message(trust_message = self.class.trust_message) ⇒ Object



47
48
49
50
# File 'lib/eve/trust/controller_helpers.rb', line 47

def deliver_trust_message(trust_message = self.class.trust_message)
  trust_uri = "http://#{request.host_with_port}/"
  headers['Eve.trustme'] = "#{trust_uri}::#{trust_message}"
end

#detect_igbObject



52
53
54
55
56
# File 'lib/eve/trust/controller_helpers.rb', line 52

def detect_igb
  if igb.igb?
    set_igb_or_default
  end
end

#igbObject



29
30
31
# File 'lib/eve/trust/controller_helpers.rb', line 29

def igb
  @igb ||= Eve::Trust::IgbInterface.new(request)
end

#prefer_trust(trust_message = self.class.trust_message) ⇒ Object



40
41
42
43
44
45
# File 'lib/eve/trust/controller_helpers.rb', line 40

def prefer_trust(trust_message = self.class.trust_message)
  if igb? && !igb.trusted?
    deliver_trust_message(trust_message)
  end
  true
end

#require_trust(trust_message = self.class.trust_message) ⇒ Object



33
34
35
36
37
38
# File 'lib/eve/trust/controller_helpers.rb', line 33

def require_trust(trust_message = self.class.trust_message)
  if igb? && !igb.trusted?
    render :text => "<body onload=\"CCPEVE.requestTrust('http://#{request.host_with_port}')\">", :layout => false
  end
  true
end

#set_igbObject



64
65
66
67
# File 'lib/eve/trust/controller_helpers.rb', line 64

def set_igb
  request.format = :igb
  igb
end

#set_igb_or_defaultObject



58
59
60
61
62
# File 'lib/eve/trust/controller_helpers.rb', line 58

def set_igb_or_default
  if default_template_exists? :igb
    set_igb
  end
end