Class: Yesterday::VersionedObject

Inherits:
Struct
  • Object
show all
Defined in:
lib/yesterday/versioned_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/yesterday/versioned_object.rb', line 32

def method_missing(method, *arguments, &block)
  if attributes.has_key?(method.to_s)
    attributes[method.to_s]
  else
    super
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes

Returns:

  • (Object)

    the current value of attributes



2
3
4
# File 'lib/yesterday/versioned_object.rb', line 2

def attributes
  @attributes
end

Instance Method Details

#created?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/yesterday/versioned_object.rb', line 16

def created?
  attributes['_event'] && attributes['_event'] == 'created'
end

#destroyed?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/yesterday/versioned_object.rb', line 20

def destroyed?
  attributes['_event'] && attributes['_event'] == 'destroyed'
end

#eventObject



8
9
10
# File 'lib/yesterday/versioned_object.rb', line 8

def event
  attributes['_event'] || 'unmodified'
end

#idObject



4
5
6
# File 'lib/yesterday/versioned_object.rb', line 4

def id
  attributes['id']
end

#modified?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/yesterday/versioned_object.rb', line 12

def modified?
  attributes['_event'] && attributes['_event'] == 'modified'
end

#touched?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/yesterday/versioned_object.rb', line 24

def touched?
  modified? || created? || destroyed?
end

#unmodified?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/yesterday/versioned_object.rb', line 28

def unmodified?
  !attributes.has_key?('_event')
end