Class: ViewModel::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/view_model/reference.rb

Overview

Key to identify a viewmodel with some kind of inherent ID (e.g. an ViewModel::ActiveRecord)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(viewmodel_class, model_id) ⇒ Reference

Returns a new instance of Reference.



6
7
8
9
# File 'lib/view_model/reference.rb', line 6

def initialize(viewmodel_class, model_id)
  @viewmodel_class = viewmodel_class
  @model_id        = model_id
end

Instance Attribute Details

#model_idObject

Returns the value of attribute model_id.



4
5
6
# File 'lib/view_model/reference.rb', line 4

def model_id
  @model_id
end

#viewmodel_classObject

Returns the value of attribute viewmodel_class.



4
5
6
# File 'lib/view_model/reference.rb', line 4

def viewmodel_class
  @viewmodel_class
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



19
20
21
22
23
# File 'lib/view_model/reference.rb', line 19

def ==(other)
  other.class             == self.class &&
    other.viewmodel_class == viewmodel_class &&
    other.model_id        == model_id
end

#hashObject



27
28
29
# File 'lib/view_model/reference.rb', line 27

def hash
  [viewmodel_class, model_id].hash
end

#inspectObject



15
16
17
# File 'lib/view_model/reference.rb', line 15

def inspect
  "<Ref:#{self}>"
end

#to_sObject



11
12
13
# File 'lib/view_model/reference.rb', line 11

def to_s
  "'#{viewmodel_class.view_name}(id=#{model_id})'"
end