Sha256: a26c02a1438223ee4be3697a9b9b2a01f0c266ca52fef7281c551212e9aa4484

Contents?: true

Size: 718 Bytes

Versions: 1

Compression:

Stored size: 718 Bytes

Contents

module Sortify
  def sort_option(name, body)
    @sort_options ||= []
    name = name.to_sym
    
    begin
      scope name, body
    rescue ArgumentError => e
      raise e
    else
      @sort_options << name
    end
  end
  
  def default_sort_option(name)
    @default_sort_option = name.to_sym
  end
  
  def sort_options
    return @sort_options
  end

  def sortify(sort_option)
    sort_option = sort_option.to_sym
    
    if @sort_options.include? sort_option
      self.send(sort_option)
    else
      begin
        self.send(@default_sort_option)
      rescue
        raise NoMethodError, "The default sort option you provided, '#{@default_sort_option.to_s}' does not exist."
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sortify-0.1.1 lib/sortify.rb