Sha256: 6a6ba7555a86618e48dcb4d206722d683c7b13a47a106306082314dbad145947

Contents?: true

Size: 742 Bytes

Versions: 18

Compression:

Stored size: 742 Bytes

Contents

module MethodOrProcHelper

  # Many times throughout the views we want to either call a method on an object
  # or instance_exec a proc passing in the object as the first parameter. This
  # method takes care of this functionality.
  #
  #   call_method_or_proc_on(@my_obj, :size) same as @my_obj.size
  # OR
  #   proc = Proc.new{|s| s.size }
  #   call_method_or_proc_on(@my_obj, proc)
  #
  def call_method_or_proc_on(obj, symbol_or_proc, options = {})
    exec = options[:exec].nil? ? true : options[:exec]
    case symbol_or_proc
    when Symbol, String
      obj.send(symbol_or_proc.to_sym)
    when Proc
      if exec
        instance_exec(obj, &symbol_or_proc)
      else
        symbol_or_proc.call(obj)
      end
    end
  end

end

Version data entries

18 entries across 18 versions & 4 rubygems

Version Path
activeadmin-0.4.1 lib/active_admin/view_helpers/method_or_proc_helper.rb
activeadmin-0.4.0 lib/active_admin/view_helpers/method_or_proc_helper.rb
andrewroth_activeadmin-0.3.4.4 lib/active_admin/view_helpers/method_or_proc_helper.rb
andrewroth_activeadmin-0.3.4.3 lib/active_admin/view_helpers/method_or_proc_helper.rb
andrewroth_activeadmin-0.3.4.2 lib/active_admin/view_helpers/method_or_proc_helper.rb
andrewroth_activeadmin-0.3.4.1 lib/active_admin/view_helpers/method_or_proc_helper.rb
andrewroth_activeadmin-0.3.4 lib/active_admin/view_helpers/method_or_proc_helper.rb
activeadmin-0.3.4 lib/active_admin/view_helpers/method_or_proc_helper.rb
activeadmin-0.3.3 lib/active_admin/view_helpers/method_or_proc_helper.rb
activeadmin-0.3.2 lib/active_admin/view_helpers/method_or_proc_helper.rb
activeadmin-0.3.1 lib/active_admin/view_helpers/method_or_proc_helper.rb
activeadmin-0.3.0 lib/active_admin/view_helpers/method_or_proc_helper.rb
nsm-activeadmin-0.2.2 lib/active_admin/view_helpers/method_or_proc_helper.rb
saulolso-activeadmin-0.2.2.1 lib/active_admin/view_helpers/method_or_proc_helper.rb
saulolso-activeadmin-0.2.2 lib/active_admin/view_helpers/method_or_proc_helper.rb
activeadmin-0.2.2 lib/active_admin/view_helpers/method_or_proc_helper.rb
activeadmin-0.2.1 lib/active_admin/view_helpers/method_or_proc_helper.rb
activeadmin-0.2.0 lib/active_admin/view_helpers/method_or_proc_helper.rb