Class: BlackStack::Workmesh::Protocol
- Inherits:
-
Object
- Object
- BlackStack::Workmesh::Protocol
- Defined in:
- lib/workmesh.rb
Overview
class Node
Instance Attribute Summary collapse
-
#entity_field_id ⇒ Object
Returns the value of attribute entity_field_id.
-
#entity_field_pull_error_description ⇒ Object
Returns the value of attribute entity_field_pull_error_description.
-
#entity_field_pull_success ⇒ Object
Returns the value of attribute entity_field_pull_success.
-
#entity_field_push_error_description ⇒ Object
Returns the value of attribute entity_field_push_error_description.
-
#entity_field_push_success ⇒ Object
Returns the value of attribute entity_field_push_success.
-
#entity_field_push_time ⇒ Object
Returns the value of attribute entity_field_push_time.
-
#entity_field_sort ⇒ Object
Returns the value of attribute entity_field_sort.
-
#entity_table ⇒ Object
Returns the value of attribute entity_table.
-
#enttity_field_pull_time ⇒ Object
Returns the value of attribute enttity_field_pull_time.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pull_function ⇒ Object
Returns the value of attribute pull_function.
-
#pull_status_access_point ⇒ Object
Returns the value of attribute pull_status_access_point.
-
#push_function ⇒ Object
Returns the value of attribute push_function.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(h) ⇒ Protocol
constructor
A new instance of Protocol.
-
#push(entity, node) ⇒ Object
execute the push function of this protocol, and update the push flags.
- #to_hash ⇒ Object
Constructor Details
#initialize(h) ⇒ Protocol
Returns a new instance of Protocol.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/workmesh.rb', line 138 def initialize(h) errors = BlackStack::Workmesh::Protocol.descriptor_errors(h) raise "The protocol descriptor is not valid: #{errors.uniq.join(".\n")}" if errors.length > 0 self.name = h[:name] self.entity_table = h[:entity_table] self.entity_field_id = h[:entity_field_id] self.entity_field_sort = h[:entity_field_sort] self.push_function = h[:push_function] self.entity_field_push_time = h[:entity_field_push_time] self.entity_field_push_success = h[:entity_field_push_success] self.entity_field_push_error_description = h[:entity_field_push_error_description] self.pull_function = h[:pull_function] self.enttity_field_pull_time = h[:entity_field_pull_time] self.entity_field_pull_success = h[:entity_field_pull_success] self.entity_field_pull_error_description = h[:entity_field_pull_error_description] end |
Instance Attribute Details
#entity_field_id ⇒ Object
Returns the value of attribute entity_field_id.
95 96 97 |
# File 'lib/workmesh.rb', line 95 def entity_field_id @entity_field_id end |
#entity_field_pull_error_description ⇒ Object
Returns the value of attribute entity_field_pull_error_description.
98 99 100 |
# File 'lib/workmesh.rb', line 98 def entity_field_pull_error_description @entity_field_pull_error_description end |
#entity_field_pull_success ⇒ Object
Returns the value of attribute entity_field_pull_success.
98 99 100 |
# File 'lib/workmesh.rb', line 98 def entity_field_pull_success @entity_field_pull_success end |
#entity_field_push_error_description ⇒ Object
Returns the value of attribute entity_field_push_error_description.
96 97 98 |
# File 'lib/workmesh.rb', line 96 def entity_field_push_error_description @entity_field_push_error_description end |
#entity_field_push_success ⇒ Object
Returns the value of attribute entity_field_push_success.
96 97 98 |
# File 'lib/workmesh.rb', line 96 def entity_field_push_success @entity_field_push_success end |
#entity_field_push_time ⇒ Object
Returns the value of attribute entity_field_push_time.
96 97 98 |
# File 'lib/workmesh.rb', line 96 def entity_field_push_time @entity_field_push_time end |
#entity_field_sort ⇒ Object
Returns the value of attribute entity_field_sort.
95 96 97 |
# File 'lib/workmesh.rb', line 95 def entity_field_sort @entity_field_sort end |
#entity_table ⇒ Object
Returns the value of attribute entity_table.
95 96 97 |
# File 'lib/workmesh.rb', line 95 def entity_table @entity_table end |
#enttity_field_pull_time ⇒ Object
Returns the value of attribute enttity_field_pull_time.
98 99 100 |
# File 'lib/workmesh.rb', line 98 def enttity_field_pull_time @enttity_field_pull_time end |
#name ⇒ Object
Returns the value of attribute name.
94 95 96 |
# File 'lib/workmesh.rb', line 94 def name @name end |
#pull_function ⇒ Object
Returns the value of attribute pull_function.
98 99 100 |
# File 'lib/workmesh.rb', line 98 def pull_function @pull_function end |
#pull_status_access_point ⇒ Object
Returns the value of attribute pull_status_access_point.
97 98 99 |
# File 'lib/workmesh.rb', line 97 def pull_status_access_point @pull_status_access_point end |
#push_function ⇒ Object
Returns the value of attribute push_function.
96 97 98 |
# File 'lib/workmesh.rb', line 96 def push_function @push_function end |
Class Method Details
.descriptor_errors(h) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/workmesh.rb', line 100 def self.descriptor_errors(h) errors = [] # validate: the key :name exists and is a string errors << "The key :name is missing" if h[:name].nil? errors << "The key :name must be an String" unless h[:name].is_a?(String) # validate: the key :entity_table exists and is an symbol errors << "The key :entity_table is missing" if h[:entity_table].nil? errors << "The key :entity_table must be an Symbol" unless h[:entity_table].is_a?(Symbol) # validate: the key :entity_field_id exists and is an symbol errors << "The key :entity_field_id is missing" if h[:entity_field_id].nil? errors << "The key :entity_field_id must be an Symbol" unless h[:entity_field_id].is_a?(Symbol) # validate: the key :entity_field_sort exists and is an symbol errors << "The key :entity_field_sort is missing" if h[:entity_field_sort].nil? errors << "The key :entity_field_sort must be an Symbol" unless h[:entity_field_sort].is_a?(Symbol) # validate: the key :push_function is null or it is a procedure #errors << "The key :push_function must be an Symbol" unless h[:push_function].nil? || h[:push_function].is_a?() # validate: if :push_function exists, the key :entity_field_push_time exists and it is a symbol errors << "The key :entity_field_push_time is missing" if h[:push_function] && h[:entity_field_push_time].nil? # validate: if :push_function exists, the key :entity_field_push_success exists and it is a symbol errors << "The key :entity_field_push_success is missing" if h[:push_function] && h[:entity_field_push_success].nil? # validate: if :push_function exists, the key :entity_field_push_error_description exists and it is a symbol errors << "The key :entity_field_push_error_description is missing" if h[:push_function] && h[:entity_field_push_error_description].nil? # valiudate: if :pull_function exists, the key :pull_status_access_point exists and it is a string errors << "The key :pull_status_access_point is missing" if h[:pull_function] && h[:pull_status_access_point].nil? errors << "The key :pull_status_access_point must be an String" unless h[:pull_function].nil? || h[:pull_status_access_point].is_a?(String) # validate: if :pull_function exists, the key :entity_field_pull_time exists and it is a symbol errors << "The key :entity_field_pull_time is missing" if h[:pull_function] && h[:entity_field_pull_time].nil? # validate: if :pull_function exists, the key :entity_field_pull_success exists and it is a symbol errors << "The key :entity_field_pull_success is missing" if h[:pull_function] && h[:entity_field_pull_success].nil? # validate: if :pull_function exists, the key :entity_field_pull_error_description exists and it is a symbol errors << "The key :entity_field_pull_error_description is missing" if h[:pull_function] && h[:entity_field_pull_error_description].nil? # return list of errors errors.uniq end |
Instance Method Details
#push(entity, node) ⇒ Object
execute the push function of this protocol, and update the push flags
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/workmesh.rb', line 173 def push(entity, node) raise 'The push function is not defined' if self.push_function.nil? entity[entity_field_push_time] = now() begin self.push_function.call(entity, node) entity[entity_field_push_success] = true entity[entity_field_push_error_description] = nil entity.save rescue => e entity[entity_field_push_success] = false entity[entity_field_push_error_description] = e. entity.save raise e end end |
#to_hash ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/workmesh.rb', line 155 def to_hash() ret = super() ret[:name] = self.name ret[:entity_table] = self.entity_table ret[:entity_field_id] = self.entity_field_id ret[:entity_field_sort] = self.entity_field_sort ret[:push_function] = self.push_function ret[:entity_field_push_time] = self.entity_field_push_time ret[:entity_field_push_success] = self.entity_field_push_success ret[:entity_field_push_error_description] = self.entity_field_push_error_description ret[:pull_function] = self.pull_function ret[:enttity_field_pull_time] = self.enttity_field_pull_time ret[:entity_field_pull_success] = self.entity_field_pull_success ret[:entity_field_pull_error_description] = self.entity_field_pull_error_description ret end |