class ARII::Helper
Helper
Class¶ ↑
> Miscellaneous helper methods and utils to deal with data.¶ ↑
Attributes
replacements[RW]
Public Class Methods
new()
click to toggle source
# File lib/arii/helper.rb, line 11 def initialize # load each helper function into a map for replacement in the delivery @replacements = [["%{ARII.date}", self.date], ["%{ARII.datetime}", self.datetime], ["%{ARII.hostname}", self.hostname]] end
validate_agent()
click to toggle source
Validate Agent
¶ ↑
> Validates Agent-specific properties¶ ↑
+ agent - the agent for validation
# File lib/arii/helper.rb, line 131 def self.validate_agent begin valid = self.validate_seed(agent[:publisher], agent[:payload]) && self.validate_payload(agent[:publisher], agent[:payload]) rescue Exception => e end valid end
validate_payload(publisher, payload)
click to toggle source
Validate payload¶ ↑
> Validates content payload.¶ ↑
+ publisher - for publisher-specific validations + payload - content for validation
# File lib/arii/helper.rb, line 56 def self.validate_payload publisher, payload @database_servers = ["mysql", "sqlite", "postgresql"] valid = true begin case publisher when 'csv', 'xml', 'json', 'file', 'js' # file content URI is mandatory if payload[:uri].nil? then valid = false end when 'sql' # check if database server is available unless database_servers.include? payload[:server] then valid = false end # database username is mandatory if payload[:username].nil? then valid = false end # database user password is mandatory if payload[:password].nil? then valid = false end # database name is mandatory if payload[:database].nil? then valid = false end # database query is mandatory if payload[:query].nil? then valid = false end end rescue Exception => e end valid end
validate_seed(publisher, seed)
click to toggle source
Validate Seed¶ ↑
> Validates Seed-specific properties¶ ↑
+ publisher - for publisher-specific validations + seed - the seed hash
# File lib/arii/helper.rb, line 107 def self.validate_seed publisher, seed begin valid = self.validate_payload publisher, seed if valid then # seed must have selectors if seed[:selectors].nil? then valid = false end else valid = false end rescue Exception => e end valid end
Public Instance Methods
date()
click to toggle source
# File lib/arii/helper.rb, line 25 def date Time.now.strftime("%Y-%m-%d").to_s end
datetime()
click to toggle source
# File lib/arii/helper.rb, line 21 def datetime Time.now.to_s end
deep_copy(object)
click to toggle source
hostname()
click to toggle source
# File lib/arii/helper.rb, line 17 def hostname ENV["APP_HOST"] end
identify_variables(text)
click to toggle source
Identify Variables¶ ↑
> Identifies variables on string set, generates array with all scanned variables for processing.¶ ↑
> Variables are enclosed in %{variable} string.¶ ↑
-
text
- string to be scanned
# File lib/arii/helper.rb, line 36 def identify_variables text begin results = Array.new text.scan(/%{(.*?)}/).each do |m| results.push m[0] end rescue Exception => e end results end