Debug Printing


def debug_code(title=nil, text=nil)
if $debug == true
if text and title
puts "------------- #{title} -------------"
puts text</span>
puts "------------- End #{title} -------------"
else</span>
puts "------------- Begin Debug -------------"
puts title</span>
puts "------------- End Debug -------------"
end
end
end

def debug_json_code(title=nil, text=nil)
if $debug == true
if text and title
Pry::ColorPrinter.pp "------------- #{title} -------------"
Pry::ColorPrinter.pp text
Pry::ColorPrinter.pp "------------- End #{title} -------------"
else
Pry::ColorPrinter.pp "------------- Begin Debug -------------"
Pry::ColorPrinter.pp title
Pry::ColorPrinter.pp "------------- End Debug -------------"
end
end
end

aws class

class AwsStuff
@@region = ""
@@dbResult = ""
def self.get_dynamodb_data(dbtable, dbkey)
 dynamodb = Aws::DynamoDB::Client.new(region: @@region) 
params = {    
table_name: dbtable, 
key: {    uuid: dbkey }
}
begin
result = dynamodb.get_item(params)
if result.item == nil
debug_code "Could not find item '#{dbkey}' in db table '#{dbtable}' "
exit 0
end
debug_code result
# save the response to the response class
Response.new(result['item'])
return result['item']
rescue Aws::DynamoDB::Errors::ServiceError => error
debug_code "Could not find item '#{dbkey}' in table '#{dbtable}' "
debug_code error.message
fail error.message
end
end
end

Helper Class

class Helper

def self.get_random_string(length=3)

source= (“A”..”Z”).to_a + (0..9).to_a
key=””
length.times{ key += source[rand(source.size)].to_s }
return key

end

def self.get_random_alphabet(length=1)

source= (“A”..”Z”).to_a
key=””
length.times{ key += source[rand(source.size)].to_s }
return key

end

def self.generate_random_uk_postcode

postcode = “#{get_random_alphabet(length=1)}#{rand(15)} #{rand(9)}#{get_random_alphabet(2)}”
return postcode

end

def self.write_json_to_location(data,location)

File.open(“#{location}.json”,”w”) do |f|
f.write(JSON.pretty_generate(data))
end

end

end