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_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.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pull_function ⇒ Object
, :enttity_field_pull_time, :entity_field_pull_success, :entity_field_pull_error_description.
-
#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.
-
#pull(node, l = nil) ⇒ Object
execute the pull function of this protocol, and update the push flags.
-
#push(entity, node, l = nil) ⇒ 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.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/workmesh.rb', line 125 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.
82 83 84 |
# File 'lib/workmesh.rb', line 82 def entity_field_id @entity_field_id end |
#entity_field_push_error_description ⇒ Object
Returns the value of attribute entity_field_push_error_description.
83 84 85 |
# File 'lib/workmesh.rb', line 83 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.
83 84 85 |
# File 'lib/workmesh.rb', line 83 def entity_field_push_success @entity_field_push_success end |
#entity_field_push_time ⇒ Object
Returns the value of attribute entity_field_push_time.
83 84 85 |
# File 'lib/workmesh.rb', line 83 def entity_field_push_time @entity_field_push_time end |
#entity_field_sort ⇒ Object
Returns the value of attribute entity_field_sort.
82 83 84 |
# File 'lib/workmesh.rb', line 82 def entity_field_sort @entity_field_sort end |
#entity_table ⇒ Object
Returns the value of attribute entity_table.
82 83 84 |
# File 'lib/workmesh.rb', line 82 def entity_table @entity_table end |
#name ⇒ Object
Returns the value of attribute name.
81 82 83 |
# File 'lib/workmesh.rb', line 81 def name @name end |
#pull_function ⇒ Object
, :enttity_field_pull_time, :entity_field_pull_success, :entity_field_pull_error_description
85 86 87 |
# File 'lib/workmesh.rb', line 85 def pull_function @pull_function end |
#pull_status_access_point ⇒ Object
Returns the value of attribute pull_status_access_point.
84 85 86 |
# File 'lib/workmesh.rb', line 84 def pull_status_access_point @pull_status_access_point end |
#push_function ⇒ Object
Returns the value of attribute push_function.
83 84 85 |
# File 'lib/workmesh.rb', line 83 def push_function @push_function end |
Class Method Details
.descriptor_errors(h) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/workmesh.rb', line 87 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
#pull(node, l = nil) ⇒ Object
execute the pull function of this protocol, and update the push flags
178 179 180 181 182 183 184 185 186 |
# File 'lib/workmesh.rb', line 178 def pull(node, l=nil) l = BlackStack::DummyLogger.new(nil) if l.nil? raise 'The pull function is not defined' if self.pull_function.nil? begin self.pull_function.call(node, l) rescue => e raise e end end |
#push(entity, node, l = nil) ⇒ Object
execute the push function of this protocol, and update the push flags
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/workmesh.rb', line 160 def push(entity, node, l=nil) l = BlackStack::DummyLogger.new(nil) if l.nil? 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, l) 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
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/workmesh.rb', line 142 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 |