Sha256: b91aab0244689fbe9c763e9d522347ccf9e0576b4651631534841de8edc6583c

Contents?: true

Size: 1.06 KB

Versions: 11

Compression:

Stored size: 1.06 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module String #:nodoc:
      module Inflections #:nodoc:

        ActiveSupport::Inflector.inflections do |inflect|
          inflect.singular("address", "address")
          inflect.singular("addresses", "address")
          inflect.irregular("canvas", "canvases")
        end

        REVERSALS = {
          "asc" => "desc",
          "ascending" => "descending",
          "desc" => "asc",
          "descending" => "ascending"
        }

        def collectionize
          tableize.gsub("/", "_")
        end

        def identify
          gsub(" ", "_").gsub(/\W/, "").dasherize.downcase
        end

        def labelize
          underscore.humanize
        end

        def invert
          REVERSALS[self]
        end

        def singular?
          singularize == self
        end

        def plural?
          pluralize == self
        end

        def reader
          writer? ? gsub("=", "") : self
        end

        def writer?
          include?("=")
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mongoid-1.1.4 lib/mongoid/extensions/string/inflections.rb
mongoid-1.1.3 lib/mongoid/extensions/string/inflections.rb
mongoid-1.1.2 lib/mongoid/extensions/string/inflections.rb
mongoid-1.1.1 lib/mongoid/extensions/string/inflections.rb
mongoid-1.1.0 lib/mongoid/extensions/string/inflections.rb
mongoid-1.0.6 lib/mongoid/extensions/string/inflections.rb
mongoid-1.0.5 lib/mongoid/extensions/string/inflections.rb
mongoid-1.0.4 lib/mongoid/extensions/string/inflections.rb
mongoid-1.0.3 lib/mongoid/extensions/string/inflections.rb
mongoid-1.0.2 lib/mongoid/extensions/string/inflections.rb
mongoid-1.0.1 lib/mongoid/extensions/string/inflections.rb