Sha256: 7fb84046cb6a426379f2f7cad888c6e4e78de2793e353f6dc64020180cac2db2

Contents?: true

Size: 1002 Bytes

Versions: 1

Compression:

Stored size: 1002 Bytes

Contents

module Spree
  #
  # Handles the pluralization of resource names for the API classes
  #
  class Inflector
    def self.inflections
      @inflections ||= []
    end

    def self.inflections=(value)
      @inflections = value
    end

    def self.pluralize(singular)
      inflection = self.inflections.detect { |i| i[:singular] == singular }
      raise UndefinedInflection unless inflection
      inflection[:plural]
    end

    def self.inflection(singular, plural)
      inflections << Inflection.new(singular, plural)
    end

    Inflection = Struct.new(:singular, :plural)

    class UndefinedInflection < Exception ; end
  end
end

Spree::Inflector.inflection 'cat', 'cats'
Spree::Inflector.inflection 'country', 'countries'
Spree::Inflector.inflection 'product', 'products'
Spree::Inflector.inflection 'product_property', 'product_properties'
Spree::Inflector.inflection 'taxonomy', 'taxonomies'
Spree::Inflector.inflection 'variant', 'variants'
Spree::Inflector.inflection 'zone', 'zones'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree-wrap-0.0.2 motion/spree/inflector.rb