Module: Wrapper

Extended by:
ActiveSupport::Concern
Defined in:
lib/wrapper.rb,
lib/wrapper/version.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



69
70
71
72
73
74
75
# File 'lib/wrapper.rb', line 69

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

Instance Method Details

#==(other) ⇒ Object

Compare #self or #resource against the given other.



52
53
54
# File 'lib/wrapper.rb', line 52

def ==(other)
  super || resource == other
end

#as_json(*args) ⇒ Object



56
57
58
# File 'lib/wrapper.rb', line 56

def as_json(*args)
  resource.as_json(*args)
end

#initialize(resource) ⇒ Object



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

def initialize(resource)
  @resource = resource
end

#modelObject

Returns the wrapped #resource‘s class.



45
46
47
# File 'lib/wrapper.rb', line 45

def model
  self.resource.class
end

#resourceObject

Returns the original, wrapped #resource.



38
39
40
# File 'lib/wrapper.rb', line 38

def resource
  @resource
end

#respond_to?(method) ⇒ Boolean

Check if an instance method is defined either in the presenter or for on the #resource.

Returns:

  • (Boolean)


64
65
66
# File 'lib/wrapper.rb', line 64

def respond_to?(method)
  super || resource.respond_to?(method)
end