class ForumSharedCode::ForumAssist

Public Class Methods

add_user_name(list) click to toggle source
# File lib/skinny_forum/forum_shared_code.rb, line 46
def self.add_user_name(list)
  list.each { |suggestion|
    suggestion[:user]=User.where(id: suggestion[:user]).pluck(:user_name)[0]
  }
  list
end
aws_params() click to toggle source
# File lib/skinny_forum/forum_shared_code.rb, line 64
def self.aws_params
  {server: 's3.amazonaws.com',
   port: 443,
   protocol: 'https',
   no_subdomains: true}
end
get_url(source,my_bucket=THE_BUCKET) click to toggle source
# File lib/skinny_forum/forum_shared_code.rb, line 72
def self.get_url(source,my_bucket=THE_BUCKET)
  if ENV['USE_AWS']=='yes'
    begin
      s3 = RightAws::S3Interface.new(ENV['S3_ACCESS_KEY_ID'], ENV['S3_SECRET_ACCESS_KEY'], AssistMe.aws_params)
      url= s3.get_link(my_bucket, source)
      temp=url.split(my_bucket)
      "https://#{my_bucket}.s3.amazonaws.com#{temp[1]}"
    rescue
      'no joy'
    end
  else
    'no joy'
  end
end
make_first(alist,params) click to toggle source
# File lib/skinny_forum/forum_shared_code.rb, line 53
def self.make_first(alist,params)
  index=0
  (0...alist.size).each {|i|
    params[:key].nil? ? (index=i if alist[i]==params[:ref]) : index=i if alist[i][params[:key]]==params[:ref]
  }
  ref=alist[index]
  alist.delete_at(index)
  alist.unshift(ref)
  alist
end
make_last(alist,params) click to toggle source
# File lib/skinny_forum/forum_shared_code.rb, line 36
def self.make_last(alist,params)
  index=0
  (0...alist.size).each {|i|
    params[:key].nil? ? (index=i if alist[i]==params[:ref]) : index=i if alist[i][params[:key]]==params[:ref]
  }
  ref=alist[index]
  alist.delete_at(index)
  alist.push(ref)
  alist
end
make_string_list(alist) click to toggle source
# File lib/skinny_forum/forum_shared_code.rb, line 6
def self.make_string_list(alist)
  plucking=''
  alist.each {|entry|
    plucking.concat(',' ) unless plucking==''
    plucking.concat(entry.to_s)
  }
  plucking
end
named_array(data,params,d2) click to toggle source
# File lib/skinny_forum/forum_shared_code.rb, line 15
def self.named_array(data,params,d2)
  data = Array.new(params.size,nil)  if data.nil? || data.empty?
  if d2 && data.size==1
    double=true
    data.push(data[0])
  end
  pseudo= d2 && (data[0].is_a?(Integer)  || data[0].nil?)
  temp=Array.new{{}}
  d2 ? size=data.size : size=1
  (0...size).each {|i|
    temp[i]={}
    d2 ? datax=data[i] : datax=data
    pseudo  ? width= 1 : width=datax.size
    (0...width).each { |j|
      pseudo ? temp[i].store(params[0], datax) : temp[i].store(params[j], datax[j]) }
    Rails.logger.debug 'hello'
  }
  temp.shift if double
  d2 ? temp : temp[0]
end
save_image(source, key) click to toggle source
# File lib/skinny_forum/forum_shared_code.rb, line 87
def self.save_image(source, key)
  amazon_s3 = RightAws::S3Interface.new(ENV['S3_ACCESS_KEY_ID'], ENV['S3_SECRET_ACCESS_KEY'], aws_params)
  amazon_s3.store_object_multipart(bucket: THE_BUCKET, key: key, data: File.read(source))
end