Module: Fortitude::Widget::AroundContent::ClassMethods

Defined in:
lib/fortitude/widget/around_content.rb

Instance Method Summary collapse

Instance Method Details

#around_content(*method_names) ⇒ Object

PUBLIC API


11
12
13
14
15
16
# File 'lib/fortitude/widget/around_content.rb', line 11

def around_content(*method_names)
  return if method_names.length == 0
  @_fortitude_around_content_methods ||= [ ]
  @_fortitude_around_content_methods += method_names.map { |x| x.to_s.strip.downcase.to_sym }
  rebuild_run_content!(:around_content_added)
end

#around_content_methodsObject

INTERNAL USE ONLY


35
36
37
38
39
40
41
42
43
# File 'lib/fortitude/widget/around_content.rb', line 35

def around_content_methods
  superclass_methods = if superclass.respond_to?(:around_content_methods)
    superclass.around_content_methods
  else
    [ ]
  end

  (superclass_methods + this_class_around_content_methods).uniq
end

#remove_around_content(*method_names) ⇒ Object

PUBLIC API


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fortitude/widget/around_content.rb', line 19

def remove_around_content(*method_names)
  options = method_names.extract_options!
  options.assert_valid_keys(:fail_if_not_present)

  not_found = [ ]
  method_names.each do |method_name|
    not_found << method_name unless (@_fortitude_around_content_methods || [ ]).delete(method_name)
  end

  rebuild_run_content!(:around_content_removed)
  unless (not_found.length == 0) || (options.has_key?(:fail_if_not_present) && (! options[:fail_if_not_present]))
    raise ArgumentError, "no such methods: #{not_found.inspect}"
  end
end