Class: ARII::Helper
- Inherits:
-
Object
- Object
- ARII::Helper
- Defined in:
- lib/arii/helper.rb
Overview
Helper Class
=> Miscellaneous helper methods and utils to deal with data.
Instance Attribute Summary collapse
-
#replacements ⇒ Object
Returns the value of attribute replacements.
Class Method Summary collapse
-
.validate_agent ⇒ Object
Validate Agent => Validates Agent-specific properties.
-
.validate_payload(publisher, payload) ⇒ Object
Validate payload => Validates content payload.
-
.validate_seed(publisher, seed) ⇒ Object
Validate Seed => Validates Seed-specific properties.
Instance Method Summary collapse
- #date ⇒ Object
- #datetime ⇒ Object
-
#deep_copy(object) ⇒ Object
Copy Object/Hash/Array...
- #hostname ⇒ Object
-
#identify_variables(text) ⇒ Object
Identify Variables => Identifies variables on string set, generates array with all scanned variables for processing.
-
#initialize ⇒ Helper
constructor
A new instance of Helper.
Constructor Details
#initialize ⇒ Helper
Returns a new instance of Helper.
11 12 13 14 |
# 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 |
Instance Attribute Details
#replacements ⇒ Object
Returns the value of attribute replacements.
8 9 10 |
# File 'lib/arii/helper.rb', line 8 def replacements @replacements end |
Class Method Details
.validate_agent ⇒ Object
Validate Agent
=> Validates Agent-specific properties
- agent - the agent for validation
131 132 133 134 135 136 137 138 139 |
# 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) ⇒ Object
Validate payload
=> Validates content payload.
- publisher - for publisher-specific validations
- payload - content for validation
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# 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) ⇒ Object
Validate Seed
=> Validates Seed-specific properties
- publisher - for publisher-specific validations
- seed - the seed hash
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# 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 |
Instance Method Details
#date ⇒ Object
25 26 27 |
# File 'lib/arii/helper.rb', line 25 def date Time.now.strftime("%Y-%m-%d").to_s end |
#datetime ⇒ Object
21 22 23 |
# File 'lib/arii/helper.rb', line 21 def datetime Time.now.to_s end |
#deep_copy(object) ⇒ Object
Copy Object/Hash/Array...
=> Copies any object into new object (overcome references).
- o - the object being copied
147 148 149 |
# File 'lib/arii/helper.rb', line 147 def deep_copy object Marshal.load(Marshal.dump(object)) end |
#hostname ⇒ Object
17 18 19 |
# File 'lib/arii/helper.rb', line 17 def hostname ENV["APP_HOST"] end |
#identify_variables(text) ⇒ Object
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
36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |