Module: Fortitude::Widget::Integration

Extended by:
ActiveSupport::Concern
Included in:
Fortitude::Widget
Defined in:
lib/fortitude/widget/integration.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

RUBY CALLBACK



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

def method_missing(name, *args, &block)
  target_method_and_args = _fortitude_target_method_and_args_for_method_missing(name, *args, &block)
  if target_method_and_args
    target = target_method_and_args[0]
    method = target_method_and_args[1]
    args = target_method_and_args[2..-1]

    target.send(method, *args, &block)
  else
    super(name, *args, &block)
  end
end

Instance Method Details

#_fortitude_allow_helper_even_without_automatic_helper_access?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/fortitude/widget/integration.rb', line 69

def _fortitude_allow_helper_even_without_automatic_helper_access?(method_name)
  false
end

#_fortitude_target_method_and_args_for_method_missing(missing_method_name, *missing_method_args, &missing_method_block) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fortitude/widget/integration.rb', line 73

def _fortitude_target_method_and_args_for_method_missing(missing_method_name, *missing_method_args, &missing_method_block)
  if self.class.extra_assigns == :use && missing_method_args.length == 0 && (! missing_method_block)
    ivar_name = self.class.instance_variable_name_for_need(missing_method_name)
    return [ self, :instance_variable_get, ivar_name ] if instance_variable_defined?(ivar_name)
  end

  if _fortitude_use_helper?(missing_method_name)
    return [ @_fortitude_rendering_context.helpers_object, missing_method_name, *missing_method_args ]
  end

  if @_fortitude_in_block_for_sub_widget
    return [ @_fortitude_in_block_for_sub_widget, missing_method_name, *missing_method_args ]
  end

  nil
end

#_fortitude_use_helper?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
# File 'lib/fortitude/widget/integration.rb', line 59

def _fortitude_use_helper?(method_name)
  unless @_fortitude_rendering_context && @_fortitude_rendering_context.helpers_object && @_fortitude_rendering_context.helpers_object.respond_to?(method_name, true)
    return false
  end

  return self.class.automatic_helper_access ||
    (self.class.respond_to?(:_fortitude_allow_helper_even_without_automatic_helper_access?) &&
     self.class._fortitude_allow_helper_even_without_automatic_helper_access?(method_name))
end

#respond_to?(name, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
# File 'lib/fortitude/widget/integration.rb', line 48

def respond_to?(name, include_all = false)
  out = super(name, include_all)

  if (! out)
    target_method_and_args = _fortitude_target_method_and_args_for_method_missing(name)
    out = true if target_method_and_args
  end

  out
end