Class: ExplicitDelegator
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/explicit_delegator.rb
Direct Known Subclasses
AssessmentFormPresenter, ContentItemPresenter, MenuWidgetPresenter, OutlineAssessmentPresenter, OutlineVideoPresenter, PageHeaderPresenter, ProfileLinkPresenter, ProfilePresenter, WoopleTheme::AnswerPresenter, WoopleTheme::BreadcrumbPresenter, WoopleTheme::ContentItem, WoopleTheme::Dashboard::AccountUserPresenter, WoopleTheme::Dashboard::ExceptionPresenter, WoopleTheme::Dashboard::OrganizationAccountPresenter, WoopleTheme::Dashboard::PointsPresenter, WoopleTheme::Dashboard::SectionPresenter, WoopleTheme::Dashboard::StatusAlertPresenter, WoopleTheme::Dashboard::UserAndStatusPresenter, WoopleTheme::QuestionPresenter, WoopleTheme::Reports::ActivityReportPresenter, WoopleTheme::Reports::ActivityReportsPresenter, WoopleTheme::VideoPresenter
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ExplicitDelegator.
16
17
18
19
20
|
# File 'lib/explicit_delegator.rb', line 16
def initialize(delegate)
@delegate = delegate
ensure_defined
end
|
Class Method Details
.enforce_definitions(*methods) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/explicit_delegator.rb', line 6
def self.enforce_definitions(*methods)
define_method(:enforced_methods) do
super() | methods
end
methods.each do |method|
def_instance_delegator(:@delegate, method)
end
end
|
Instance Method Details
#enforced_methods ⇒ Object
22
23
24
|
# File 'lib/explicit_delegator.rb', line 22
def enforced_methods
[]
end
|
#ensure_defined ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/explicit_delegator.rb', line 26
def ensure_defined
missing_methods = []
enforced_methods.each do |method|
missing_methods << method unless @delegate.methods.include?(method)
end
raise "Methods required to use #{self.class}: #{missing_methods}" unless missing_methods.empty?
end
|