Sha256: 6d7749f82b24b88386dddac3b14bf8f684ce8bf32188f6c60bb3c7479db83000

Contents?: true

Size: 766 Bytes

Versions: 11

Compression:

Stored size: 766 Bytes

Contents

module BestInPlace
  module Utils #:nodoc:
    module_function
    def build_best_in_place_id(object, field)
      case object
        when Symbol, String
          "best_in_place_#{object}_#{field}"
        else
          id = "best_in_place_#{object_to_key(object)}"
          id << "_#{object.id}" if object.persisted?
          id << "_#{field}"
          id
      end
    end

    def object_to_key(object)
      model_name_from_record_or_class(object).param_key
    end

    def convert_to_model(object)
      object.respond_to?(:to_model) ? object.to_model : object
    end

    def model_name_from_record_or_class(record_or_class)
      (record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name
    end

  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
best_in_place-4.0.0 lib/best_in_place/utils.rb
best_in_place-3.1.1 lib/best_in_place/utils.rb
best_in_place-3.1.0 lib/best_in_place/utils.rb
in_place_edit_with_datepicker-1.0.0 lib/best_in_place/utils.rb
in_place_edit_with_datepicker-0.0.2 lib/best_in_place/utils.rb
in_place_edit_with_datepicker-0.0.1 lib/best_in_place/utils.rb
best_in_place-3.0.3 lib/best_in_place/utils.rb
best_in_place-3.0.2 lib/best_in_place/utils.rb
best_in_place-3.0.1 lib/best_in_place/utils.rb
best_in_place-3.0.0 lib/best_in_place/utils.rb
best_in_place-3.0.0.rc1 lib/best_in_place/utils.rb