lib/cloud_powers/helper.rb in cloud_powers-0.2.3 vs lib/cloud_powers/helper.rb in cloud_powers-0.2.4
- old
+ new
@@ -1,10 +1,10 @@
require 'logger'
require 'pathname'
+require 'uri'
require 'syslog/logger'
require_relative 'smash_error'
-require 'byebug'
module Smash
module CloudPowers
module Helper
@@ -14,10 +14,17 @@
value = yield key if block_given?
instance_variable_set(key, value) unless instance_variable_get(to_i_var(key))
end
end
+ # This is a way to find out if you are trying to work with a resource
+ # available to CloudPowers
+ # === @returns <Array>
+ def available_resources
+ [:Task].concat(Smash::CloudPowers.constants)
+ end
+
def called_from
File.expand_path(File.dirname($0))
end
def create_logger
@@ -72,10 +79,14 @@
tries += 1
sleep 1
end
end
+ def symbolize_keys(hash)
+ hash.inject({}) { |carry, (k, v)| carry.tap { |h| h[k.to_sym] = v } }
+ end
+
# Gives the path from the project root to lib/tasks[/#{file}.rb]
# @params:
# * [file] <String>: name of a file
# @returns:
# * path[/file] <String>
@@ -155,9 +166,13 @@
JSON.parse(json)
true
rescue Exception => e
false
end
+ end
+
+ def valid_url?(url)
+ url =~ /\A#{URI::regexp}\z/
end
end
end
end