Class: Cyrax::Decorator

Inherits:
Wrapper show all
Includes:
ActiveModel::Serialization, ActiveModel::Serializers::JSON, ActiveModel::Serializers::Xml
Defined in:
lib/cyrax/decorator.rb

Instance Attribute Summary

Attributes inherited from Wrapper

#accessor, #options, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Wrapper

#initialize

Constructor Details

This class inherits a constructor from Cyrax::Wrapper

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



19
20
21
22
# File 'lib/cyrax/decorator.rb', line 19

def method_missing(method, *args, &block)
  return super unless resource.respond_to?(method)
  resource.send(method, *args, &block)
end

Class Method Details

.decorate_collection(resource) ⇒ Object



31
32
33
# File 'lib/cyrax/decorator.rb', line 31

def decorate_collection(resource)
  Cyrax::Presenters::DecoratedCollection.decorate(resource, decorator: self)
end

Instance Method Details

#respond_to?(method_sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/cyrax/decorator.rb', line 24

def respond_to?(method_sym, include_private = false)
  super || resource.respond_to?(method_sym, include_private)
end

#to_modelObject



7
8
9
# File 'lib/cyrax/decorator.rb', line 7

def to_model
  resource
end

#to_paramObject



11
12
13
# File 'lib/cyrax/decorator.rb', line 11

def to_param
  resource.to_param
end

#to_partial_pathObject



15
16
17
# File 'lib/cyrax/decorator.rb', line 15

def to_partial_path
  resource.to_partial_path
end