Class: Conflict::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/conflict/domain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, action, resource, created = Time.now, ttl = TTL) ⇒ Event

should at least make constants for event types ?

Raises:



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

#actionObject (readonly)

Returns the value of attribute action.



49
50
51
# File 'lib/conflict/domain.rb', line 49

def action
  @action
end

#clientObject (readonly)

Returns the value of attribute client.



49
50
51
# File 'lib/conflict/domain.rb', line 49

def client
  @client
end

#resourceObject (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

Returns:

  • (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

#expiresObject



88
89
90
# File 'lib/conflict/domain.rb', line 88

def expires
  @created_time + @ttl
end

#to_sObject



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_xmlObject



84
85
86
# File 'lib/conflict/domain.rb', line 84

def to_xml
  '<event client="' + self.client.gsub("<", "&lt;") + '" action="' + self.action + '" resource="' + self.resource.gsub("<", "&lt;") + '" />'
end

#to_yaml_propertiesObject



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