Class: Conflict::Event
- Inherits:
-
Object
- Object
- Conflict::Event
- Defined in:
- lib/conflict/domain.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #expires ⇒ Object
-
#initialize(client, action, resource, created = Time.now, ttl = TTL) ⇒ Event
constructor
should at least make constants for event types ?.
- #to_s ⇒ Object
- #to_xml ⇒ Object
- #to_yaml_properties ⇒ Object
Constructor Details
#initialize(client, action, resource, created = Time.now, ttl = TTL) ⇒ Event
should at least make constants for event types ?
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/conflict/domain.rb', line 52 def initialize client, action, resource, created=Time.now, ttl=TTL raise ConflictException::new("invalid action '" + action.to_s + "'") if ! ['added', 'changed', 'deleted'].index(action) raise ConflictException::new("client must not be empty value") if client.nil? or client.empty? raise ConflictException::new("resource must not be empty value") if resource.nil? or resource.empty? raise ConflictException::new("ttl cannot be negative") if ttl < 0 @client, @action, @resource = client, action, resource # kept around for staleness expiration @created_time = created # rendered in YAML @created = created.year.to_s + "/" + created.month.to_s + "/" + created.day.to_s + " " + created.hour.to_s + ":" + created.min.to_s @ttl = ttl @reserved = '' end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
49 50 51 |
# File 'lib/conflict/domain.rb', line 49 def action @action end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
49 50 51 |
# File 'lib/conflict/domain.rb', line 49 def client @client end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
49 50 51 |
# File 'lib/conflict/domain.rb', line 49 def resource @resource end |
Instance Method Details
#eql?(other) ⇒ Boolean
67 68 69 |
# File 'lib/conflict/domain.rb', line 67 def eql? other @client.eql?(other.client) and @action.eql?(other.action) and @resource.eql?(other.resource) end |
#expires ⇒ Object
88 89 90 |
# File 'lib/conflict/domain.rb', line 88 def expires @created_time + @ttl end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/conflict/domain.rb', line 71 def to_s self.class.to_s + ":" + @client.to_s + " " + @action.to_s + " " + resource.to_s end |
#to_xml ⇒ Object
84 85 86 |
# File 'lib/conflict/domain.rb', line 84 def to_xml '<event client="' + self.client.gsub("<", "<") + '" action="' + self.action + '" resource="' + self.resource.gsub("<", "<") + '" />' end |
#to_yaml_properties ⇒ Object
75 76 77 78 79 80 |
# File 'lib/conflict/domain.rb', line 75 def to_yaml_properties fields = self.instance_variables.clone fields.delete "@created_time" # keep data/time out of integration point ( ruby != java != .net ) fields.delete "@ttl" fields.sort end |