Included Modules

Class/Module Index [+]

Quicksearch

ApplicationHelper

Public Instance Methods

action_method(action, collection) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 47
def action_method(action, collection)
  collections[collection].operations[action.to_sym].method
end
action_url() click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 185
def action_url
  if [:index].include?(@operation.name)
    api_url_for("#{@collection.name.to_s}")
  elsif [:show, :stop, :start, :reboot, :attach, :detach].include?(@operation.name)
    api_url_for("#{@collection.name.to_s}/:id/#{@operation.name}")
  elsif [:destroy].include?(@operation.name)
    api_url_for("#{@collection.name.to_s}/:id")
  else
    api_url_for("#{@collection.name}/#{@operation.name}")
  end
end
cdata(text = nil, &block) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 145
def cdata(text = nil, &block)
  text ||= capture_haml(&block)
  "<![CDATA[#{text.strip}]]>"
end
driver_auth_feature_name() click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 59
def driver_auth_feature_name
  return 'key' if driver_has_feature?(:authentication_key)
  return 'password' if driver_has_feature?(:authentication_password)
end
driver_has_auth_features?() click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 55
def driver_has_auth_features?
  driver_has_feature?(:authentication_password) || driver_has_feature?(:authentication_key)
end
driver_has_bucket_location_feature?() click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 64
def driver_has_bucket_location_feature?
  driver.features(:buckets).each do |feat|
    return true if feat.name == :bucket_location
  end
  false
end
driver_has_feature?(feature_name, collection_name = :instances) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 51
def driver_has_feature?(feature_name, collection_name = :instances)
  not driver.features(collection_name).select{ |f| f.name.eql?(feature_name) }.empty?
end
driver_provider(d) click to toggle source

Reverse the entrypoints hash for a driver from drivers.yaml; note that d is a hash, not an actual driver object

# File lib/deltacloud/helpers/application_helper.rb, line 211
def driver_provider(d)
  result = {}
  if d[:entrypoints]
    d[:entrypoints].each do |kind, details|
      details.each do |prov, url|
        result[prov] ||= {}
        result[prov][kind] = url
      end
    end
  end
  result
end
filter_all(model) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 71
def filter_all(model)
    filter = {}
    filter.merge!(:id => params[:id]) if params[:id]
    filter.merge!(:architecture => params[:architecture]) if params[:architecture]
    filter.merge!(:owner_id => params[:owner_id]) if params[:owner_id]
    filter.merge!(:state => params[:state]) if params[:state]
    filter = {} if filter.keys.size.eql?(0)
    singular = model.to_s.singularize.to_sym
    @benchmark = Benchmark.measure do
      @elements = driver.send(model.to_sym, credentials, filter)
    end
    headers['X-Backend-Runtime'] = @benchmark.real.to_s
    instance_variable_set(:"@#{model}", @elements)
    respond_to do |format|
      format.html { haml :"#{model}/index" }
      format.xml { haml :"#{model}/index" }
      format.json { convert_to_json(singular, @elements) }
    end
end
header(title, opts={}, &block) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 224
def header(title, opts={}, &block)
  opts[:theme] ||= 'b'
  opts[:back] ||= 'true'
  capture_haml do
    haml_tag :div, :'data-role' => :header, :'data-theme' => opts[:theme], :'data-add-back-btn' => opts[:back] do
      haml_tag :a, :'data-rel' => :back do
        haml_concat "Back"
      end if opts[:back] == 'true'
      haml_tag :h1 do
        haml_concat title
      end
      block.call if block_given?
    end
  end
end
image_for_state(state) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 197
def image_for_state(state)
  state_img = "stopped" if (state!='RUNNING' or state!='PENDING')
  "<img src='/images/#{state.downcase}.png' title='#{state}'/>"
end
instance_action(name) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 119
def instance_action(name)
  original_instance = driver.instance(credentials, :id => params[:id])

  # If original instance doesn't include called action
  # return with 405 error (Method is not Allowed)
  unless driver.instance_actions_for(original_instance.state).include?(name.to_sym)
    return report_error(405)
  end

  @instance = driver.send(:"#{name}_instance", credentials, params["id"])

  if name == :destroy or @instance.class!=Instance
    respond_to do |format|
      format.xml { return 204 }
      format.json { return 204 }
      format.html { return redirect(instances_url) }
    end
  end

  respond_to do |format|
    format.xml { haml :"instances/show" }
    format.html { haml :"instances/show" }
    format.json {convert_to_json(:instance, @instance) }
  end
end
instance_action_method(action) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 43
def instance_action_method(action)
  action_method(action, :instances)
end
new_blob_form_url(bucket) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 264
def new_blob_form_url(bucket)
  bucket_url(@bucket.name) + "/" + NEW_BLOB_FORM_ID
end
render_cdata(text) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 150
def render_cdata(text)
  "<![CDATA[#{text.strip}]]>"
end
report_error(code=nil) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 108
def report_error(code=nil)
  @error, @code = request.env['sinatra.error'], code
  @code = 500 if not @code and not @error.class.method_defined? :code
  response.status = @code || @error.code
  respond_to do |format|
    format.xml {  haml :"errors/#{@code || @error.code}", :layout => false }
    format.json { json_return_error(@error) }
    format.html { haml :"errors/#{@code || @error.code}", :layout => :error }
  end
end
show(model) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 91
def show(model)
  @benchmark = Benchmark.measure do
    @element = driver.send(model, credentials, { :id => params[:id]} )
  end
  headers['X-Backend-Runtime'] = @benchmark.real.to_s
  instance_variable_set("@#{model}", @element)
  if @element
    respond_to do |format|
      format.html { haml :"#{model.to_s.pluralize}/show" }
      format.xml { haml :"#{model.to_s.pluralize}/show" }
      format.json { convert_to_json(model, @element) }
    end
  else
      report_error(404)
  end
end
subheader(title, opts={}) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 240
def subheader(title, opts={})
  opts[:theme] ||= 'a'
  capture_haml do
    haml_tag :div, :'data-role' => :header, :'data-theme' => opts[:theme] do
      haml_tag :p, :class => 'inner-right' do
        haml_concat title
      end
    end
  end
end
translate_error_code(code) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 251
def translate_error_code(code)
  case code
    when 400; { :message => "Bad Request" }
    when 401; { :message => "Unauthorized" }
    when 403; { :message => "Forbidden" }
    when 404; { :message => "Not Found" }
    when 405; { :message => "Method Not Allowed" }
    when 406; { :message => "Not Acceptable" }
    when 500; { :message => "Internal Server Error" }
    when 502; { :message => "Backend Server Error" }
  end
end
truncate_words(text, length = 10) click to toggle source
# File lib/deltacloud/helpers/application_helper.rb, line 202
def truncate_words(text, length = 10)
  return nil unless text
  return text if text.length<=length
  end_string = "...#{text[(text.length-(length/2))..text.length]}"
  "#{text[0..(length/2)]}#{end_string}"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.