Class: EpiDecorator::Base
- Inherits:
-
Delegator
- Object
- Delegator
- EpiDecorator::Base
- Defined in:
- lib/epi_decorator/base.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
(also: #source, #model)
Returns the value of attribute object.
Class Method Summary collapse
- .collection_decorator_class ⇒ Object
- .decorate(object) ⇒ Object
- .decorate_collection(collection, with: self) ⇒ Object
- .decorates(object_class) ⇒ Object
- .decorates_association(association, options = {}) ⇒ Object
- .decorates_associations(*associations) ⇒ Object
- .method_missing(method, *args, &block) ⇒ Object
- .respond_to_missing?(method, include_private = false) ⇒ Boolean
Instance Method Summary collapse
- #!=(other) ⇒ Object
- #==(other) ⇒ Object
- #__getobj__ ⇒ Object
- #__setobj__(obj) ⇒ Object
- #decorate ⇒ Object
- #decorated? ⇒ Boolean
-
#initialize(object) ⇒ Base
constructor
A new instance of Base.
- #instance_of?(klass) ⇒ Boolean
- #kind_of?(klass) ⇒ Boolean (also: #is_a?)
Constructor Details
#initialize(object) ⇒ Base
Returns a new instance of Base.
9 10 11 |
# File 'lib/epi_decorator/base.rb', line 9 def initialize(object) self.object = object end |
Instance Attribute Details
#object ⇒ Object Also known as: source, model
Returns the value of attribute object.
4 5 6 |
# File 'lib/epi_decorator/base.rb', line 4 def object @object end |
Class Method Details
.collection_decorator_class ⇒ Object
75 76 77 |
# File 'lib/epi_decorator/base.rb', line 75 def self.collection_decorator_class ::EpiDecorator::CollectionDecorator end |
.decorate(object) ⇒ Object
46 47 48 |
# File 'lib/epi_decorator/base.rb', line 46 def self.decorate(object) new(object) end |
.decorate_collection(collection, with: self) ⇒ Object
50 51 52 |
# File 'lib/epi_decorator/base.rb', line 50 def self.decorate_collection(collection, with: self) collection_decorator_class.new(collection, with: with) end |
.decorates(object_class) ⇒ Object
79 80 81 |
# File 'lib/epi_decorator/base.rb', line 79 def self.decorates(object_class) @object_class = object_class.to_s.camelize.constantize end |
.decorates_association(association, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/epi_decorator/base.rb', line 54 def self.decorates_association(association, = {}) define_method association do association_data = object.send(association) return if association_data.nil? decorator_class = [:with] || association_data.decorator_class if association_data.respond_to?(:map) decorator_class.decorate_collection association_data else decorator_class.decorate association_data end end end |
.decorates_associations(*associations) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/epi_decorator/base.rb', line 68 def self.decorates_associations(*associations) = associations. associations.each do |association| decorates_association association, end end |
.method_missing(method, *args, &block) ⇒ Object
83 84 85 86 87 |
# File 'lib/epi_decorator/base.rb', line 83 def self.method_missing(method, *args, &block) return super unless delegatable?(method) object_class.send(method, *args, &block) end |
.respond_to_missing?(method, include_private = false) ⇒ Boolean
89 90 91 |
# File 'lib/epi_decorator/base.rb', line 89 def self.respond_to_missing?(method, include_private = false) super || delegatable?(method) end |
Instance Method Details
#!=(other) ⇒ Object
25 26 27 |
# File 'lib/epi_decorator/base.rb', line 25 def !=(other) !(self == other) end |
#==(other) ⇒ Object
21 22 23 |
# File 'lib/epi_decorator/base.rb', line 21 def ==(other) super || other == self.object end |
#__getobj__ ⇒ Object
13 14 15 |
# File 'lib/epi_decorator/base.rb', line 13 def __getobj__ self.object end |
#__setobj__(obj) ⇒ Object
17 18 19 |
# File 'lib/epi_decorator/base.rb', line 17 def __setobj__(obj) self.object = obj end |
#decorate ⇒ Object
38 39 40 |
# File 'lib/epi_decorator/base.rb', line 38 def decorate self end |
#decorated? ⇒ Boolean
42 43 44 |
# File 'lib/epi_decorator/base.rb', line 42 def decorated? true end |
#instance_of?(klass) ⇒ Boolean
34 35 36 |
# File 'lib/epi_decorator/base.rb', line 34 def instance_of?(klass) super || object.instance_of?(klass) end |
#kind_of?(klass) ⇒ Boolean Also known as: is_a?
29 30 31 |
# File 'lib/epi_decorator/base.rb', line 29 def kind_of?(klass) super || object.kind_of?(klass) end |