This file is indexed.

/usr/lib/ruby/vendor_ruby/ramaze/controller.rb is in ruby-ramaze 2012.12.08-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#          Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the MIT license.

module Ramaze
  ##
  # Ramaze::Controller is the base controller of all controllers when developing
  # applications in Ramaze. It acts as a nice wrapper around Innate::Node and
  # allows for a more traditional MVC approach.
  #
  # @example An example controller
  #  class Posts < Ramaze::Controller
  #    map '/posts'
  #
  #    def index
  #
  #    end
  #  end
  #
  # @author Michael Fellinger
  # @since  04-01-2009
  #
  class Controller
    include Innate::Traited
    include Innate::Node

    # we are no mapped node
    Innate::Node::NODE_LIST.delete(self)

    # call our setup method one startup
    Ramaze.options.setup << self

    CONTROLLER_LIST = Set.new

    trait :app => :pristine
    trait :skip_controller_map => false

    ##
    # Hash containing the names of two common controller names and the URIs they
    # should be mapped to.
    #
    # @author Michael Fellinger
    # @since  04-01-2009
    #
    IRREGULAR_MAPPING = {
      'Controller'     => nil,
      'MainController' => '/'
    }

    ##
    # Modifies the extending class so that it's properly set up to be used as a
    # controller.
    #
    # @author Michael Fellinger
    # @since  04-01-2009
    # @param  [Class] into The class that extended Ramaze::Controller (or a sub
    #  class).
    #
    def self.inherited(into)
      Innate::Node.included(into)
      into.helper(:layout)
      CONTROLLER_LIST << into
      into.trait :skip_node_map => true
    end

    ##
    # Sets all the controllers up and loads a default controller in case no
    # custom ones have been specified.
    #
    # @author Michael Fellinger
    # @since  04-01-2009
    #
    def self.setup
      case CONTROLLER_LIST.size
      when 0
        require 'ramaze/controller/default'
      when 1
        controller = CONTROLLER_LIST.to_a.first

        begin
          controller.mapping
        rescue
          controller.map '/'
        end

        controller.setup_procedure
      else
        CONTROLLER_LIST.each do |list_controller|
          list_controller.setup_procedure
        end
      end
    end

    ##
    # Method that's used to setup each controller, called by
    # Ramaze::Controller.setup.
    #
    # @author Michael Fellinger
    # @since  04-01-2009
    #
    def self.setup_procedure
      unless ancestral_trait[:provide_set]
        engine(:etanni)
        trait(:provide_set => false)
      end

      map(generate_mapping(name)) unless trait[:skip_controller_map]
    end

    ##
    # Sets the view engine to use for pages with a content type of text/html.
    #
    # @example
    #  class Posts < Ramaze::Controller
    #    engine :etanni
    #  end
    #
    # @author Michael Fellinger
    # @since  04-01-2009
    # @param  [#to_sym] name The name of the view engine to use.
    #
    def self.engine(name)
      provide(:html, name.to_sym)
    end

    ##
    # Returns the URI a controller is mapped to.
    #
    # @author Michael Fellinger
    # @since  04-01-2009
    # @return [String]
    #
    def self.mapping
      Ramaze.to(self)
    end

    ##
    # Generates a URI for the full namespace of a class. If a class is named
    # A::B::C the URI would be /a/b/c.
    #
    # @author Michael Fellinger
    # @since  04-01-2009
    # @param  [String] klass_name The name of the class for which to generate
    #  the mapping, defaults to the current class.
    # @return [String]
    #
    def self.generate_mapping(klass_name = self.name)
      chunks = klass_name.to_s.split(/::/)
      return if chunks.empty?

      last = chunks.last

      if IRREGULAR_MAPPING.key?(last)
        irregular = IRREGULAR_MAPPING[last]
        return irregular if irregular.nil?  || chunks.size == 1
        chunks.pop
        chunks << irregular
      end

      chunks.unshift ''
      chunks.last.sub!(/Controller$/, '')
      chunks.map{|chunk| chunk.snake_case }.join('/').squeeze('/')
    end

    ##
    # Maps the current class to the specified location.
    #
    # @author Michael Fellinger
    # @since  04-01-2009
    # @param  [String] location The URI to map the controller to.
    # @param  [String] app_name The name of the application the controller
    #  belongs to.
    #
    def self.map(location, app_name = nil)
      if app_name
        trait :app => app_name
      else
        app_name = ancestral_trait[:app]
      end

      trait :skip_controller_map => true

      App.find_or_create(app_name).map(location, self)
    end

    ##
    # Returns the application to which the controller belongs to.
    #
    # @author Michael Fellinger
    # @since  04-01-2009
    # @return [Ramaze::App]
    #
    def self.app
      App[ancestral_trait[:app]]
    end

    ##
    # Returns all the options for the application the controller belongs to.
    #
    # @author Michael Fellinger
    # @since  04-01-2009
    # @return [Innate::Options]
    #
    def self.options
      return unless app = self.app
      app.options
    end
  end # Controller
end # Ramaze