Sha256: 6d8c44b8dad5a703cc2a79a5b3de3f913cbb9bc3cec06f737c45a8a93b0f4f50

Contents?: true

Size: 664 Bytes

Versions: 18

Compression:

Stored size: 664 Bytes

Contents

module ObjectAttorney

  module Helpers

    extend self

    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

18 entries across 18 versions & 1 rubygems

Version Path
object_attorney-2.10.5 lib/object_attorney/helpers.rb
object_attorney-2.10.3 lib/object_attorney/helpers.rb
object_attorney-2.10.2 lib/object_attorney/helpers.rb
object_attorney-2.10.1 lib/object_attorney/helpers.rb
object_attorney-2.9.4 lib/object_attorney/helpers.rb
object_attorney-2.9.3 lib/object_attorney/helpers.rb
object_attorney-2.9.2 lib/object_attorney/helpers.rb
object_attorney-2.9.0 lib/object_attorney/helpers.rb
object_attorney-2.8.1 lib/object_attorney/helpers.rb
object_attorney-2.8.0 lib/object_attorney/helpers.rb
object_attorney-2.6.12 lib/object_attorney/helpers.rb
object_attorney-2.6.11 lib/object_attorney/helpers.rb
object_attorney-2.6.10 lib/object_attorney/helpers.rb
object_attorney-2.6.9 lib/object_attorney/helpers.rb
object_attorney-2.6.1 lib/object_attorney/helpers.rb
object_attorney-2.6.0 lib/object_attorney/helpers.rb
object_attorney-2.5.9 lib/object_attorney/helpers.rb
object_attorney-2.5.7 lib/object_attorney/helpers.rb