Class: Mongoid::Publishable::UnpublishedObject

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/publishable/unpublished_object.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ UnpublishedObject

Returns a new instance of UnpublishedObject.



10
11
12
13
14
15
16
17
18
# File 'lib/mongoid/publishable/unpublished_object.rb', line 10

def initialize(options = {})
  if options[:model]
    @source_object = options[:model]
  elsif options[:data]
    @serialized_data = options[:data]
  else
    raise ArgumentError, "No :model or :data provided"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

delegation to the source object



36
37
38
39
40
41
42
# File 'lib/mongoid/publishable/unpublished_object.rb', line 36

def method_missing(method, *args, &block)
  if respond_to_missing?(method)
    source_object.send(method, *args, &block)
  else
    super
  end
end

Class Method Details

.deserialize_from_session(data) ⇒ Object



6
7
8
# File 'lib/mongoid/publishable/unpublished_object.rb', line 6

def self.deserialize_from_session(data)
  new(data: data)
end

Instance Method Details

#respond_to_missing?(method, include_private = false) ⇒ Boolean

delegation to the source object

Returns:

  • (Boolean)


31
32
33
# File 'lib/mongoid/publishable/unpublished_object.rb', line 31

def respond_to_missing?(method, include_private = false)
  source_object.respond_to?(method) || super
end

#serialize_for_sessionObject

returns the data needed for object retrieval



21
22
23
# File 'lib/mongoid/publishable/unpublished_object.rb', line 21

def serialize_for_session
  @serialized_data ||= serialize_object_for_session
end

#source_objectObject

returns the retrieved object



26
27
28
# File 'lib/mongoid/publishable/unpublished_object.rb', line 26

def source_object
  @source_object ||= load_source_object_from_params
end