Sha256: 761738b16777d6a00b810101e54de0808b49695b1d518515d763e46ba21471d2

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# encoding: UTF-8

require 'nokogiri'

require 'shapewear/version'
require 'shapewear/logging'
require 'shapewear/dsl'
require 'shapewear/wsdl'
require 'shapewear/request'

module Shapewear
  def self.included(receiver)
    receiver.extend(Shapewear::Logging)
    receiver.extend(Shapewear::DSL)
    receiver.extend(Shapewear::WSDL)
    receiver.extend(Shapewear::Request)

    class << receiver
      def method_added(m)
        # automatically creates an operation for each method added
        operation m
      end
    end
  end
end

# defines String.camelize and String.underscore, if it is not defined by, e.g. Rails
class String
  unless ''.respond_to? :camelize
    def camelize(first_letter_in_uppercase = true)
      if first_letter_in_uppercase
        self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
      else
        self.to_s[0].chr.downcase + self.camelize[1..-1]
      end
    end
  end

  unless ''.respond_to? :underscore
    def underscore
      word = self.to_s.dup
      word.gsub!(/::/, '/')
      word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
      word.tr!("-", "_")
      word.downcase!
      word
    end
  end
end

class Object
  def camelize_if_symbol(first_letter_in_uppercase = true)
    if is_a?(Symbol) then
      to_s.camelize(first_letter_in_uppercase)
    else
      to_s
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shapewear-0.1.5 lib/shapewear.rb