Sha256: 8aa179fa233a3cc31c0803759cbd4636db52389008da377017dffac91c7fd095

Contents?: true

Size: 805 Bytes

Versions: 6

Compression:

Stored size: 805 Bytes

Contents

module ObjectAttorney

  module Helpers

    extend self

    def marked_for_destruction?(object)
      object.respond_to?(:marked_for_destruction?) ? object.marked_for_destruction? : false
    end

    def is_integer?(string)
      string.match(/^(\d)+$/)
    end
    
    def singularize(class_name)
      class_name = class_name.to_s
      plural?(class_name) ? class_name.singularize : class_name
    end

    def plural?(string)
      string = string.to_s
      string == string.pluralize
    end

    def try_or_return(object, method, default_value)
      returning_value = object.try(method)
      returning_value.nil? ? default_value : returning_value
    end

    def has_errors_method?(object)
      object.present? && object.respond_to?(:errors) && !object.errors.nil?
    end
    
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
object_attorney-2.10.12 lib/object_attorney/helpers.rb
object_attorney-2.10.11 lib/object_attorney/helpers.rb
object_attorney-2.10.10 lib/object_attorney/helpers.rb
object_attorney-2.10.9 lib/object_attorney/helpers.rb
object_attorney-2.10.7 lib/object_attorney/helpers.rb
object_attorney-2.10.6 lib/object_attorney/helpers.rb