repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
github/markup | https://github.com/github/markup/blob/2b0e7f216904253092c90754cd95aac6d499583d/lib/github/markup/markdown.rb | lib/github/markup/markdown.rb | require "github/markup/implementation"
module GitHub
module Markup
class Markdown < Implementation
MARKDOWN_GEMS = {
"commonmarker" => proc { |content, options: {}|
commonmarker_opts = [:GITHUB_PRE_LANG].concat(options.fetch(:commonmarker_opts, []))
commonmarker_exts = options.f... | ruby | MIT | 2b0e7f216904253092c90754cd95aac6d499583d | 2026-01-04T15:41:08.109033Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/bench.rb | bench.rb | require File.expand_path("../test/helper", __FILE__)
require "ffaker"
N = 10000
def transaction
ActiveRecord::Base.transaction do
yield
raise ActiveRecord::Rollback
end
end
class Array
def rand
self[Kernel.rand(length)]
end
end
Book = Class.new ActiveRecord::Base
class Journalist < ActiveRecor... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/guide.rb | guide.rb | #!/usr/bin/env ruby
# This script generates the Guide.md file included in the Yard docs.
def comments_from path
path = File.expand_path("../lib/friendly_id/#{path}", __FILE__)
matches = File.read(path).match(/\n\s*# @guide begin\n(.*)\s*# @guide end/m)
return if matches.nil?
match = matches[1].to_s
match.... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/gemfiles/Gemfile.rails-7.2.rb | gemfiles/Gemfile.rails-7.2.rb | source "https://rubygems.org"
gemspec path: "../"
gem "activerecord", "~> 7.2.0"
gem "railties", "~> 7.2.0"
# Database Configuration
group :development, :test do
platforms :jruby do
gem "activerecord-jdbcmysql-adapter", "~> 61.0"
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
gem "kramdown"
end... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/gemfiles/Gemfile.rails-6.0.rb | gemfiles/Gemfile.rails-6.0.rb | source "https://rubygems.org"
gemspec path: "../"
gem "activerecord", "~> 6.0.0"
gem "railties", "~> 6.0.0"
# Database Configuration
group :development, :test do
platforms :jruby do
gem "activerecord-jdbcmysql-adapter", "~> 51.1"
gem "activerecord-jdbcpostgresql-adapter", "~> 51.1"
gem "kramdown"
end... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/gemfiles/Gemfile.rails-7.1.rb | gemfiles/Gemfile.rails-7.1.rb | source "https://rubygems.org"
gemspec path: "../"
gem "activerecord", "~> 7.1.0"
gem "railties", "~> 7.1.0"
# Database Configuration
group :development, :test do
platforms :jruby do
gem "activerecord-jdbcmysql-adapter", "~> 61.0"
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
gem "kramdown"
end... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/gemfiles/Gemfile.rails-7.0.rb | gemfiles/Gemfile.rails-7.0.rb | source "https://rubygems.org"
gemspec path: "../"
gem "activerecord", "~> 7.0.0"
gem "railties", "~> 7.0.0"
# Database Configuration
group :development, :test do
platforms :jruby do
gem "activerecord-jdbcmysql-adapter", "~> 61.0"
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
gem "kramdown"
end... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/gemfiles/Gemfile.rails-6.1.rb | gemfiles/Gemfile.rails-6.1.rb | source "https://rubygems.org"
gemspec path: "../"
gem "activerecord", "~> 6.1.4"
gem "railties", "~> 6.1.4"
# Database Configuration
group :development, :test do
platforms :jruby do
gem "activerecord-jdbcmysql-adapter", "~> 61.0"
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
gem "kramdown"
end... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/gemfiles/Gemfile.rails-8.0.rb | gemfiles/Gemfile.rails-8.0.rb | source "https://rubygems.org"
gemspec path: "../"
gem "activerecord", "~> 8.0.0"
gem "railties", "~> 8.0.0"
# Database Configuration
group :development, :test do
platforms :jruby do
gem "activerecord-jdbcmysql-adapter", "~> 61.0"
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
gem "kramdown"
end... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/simple_i18n_test.rb | test/simple_i18n_test.rb | require "helper"
class SimpleI18nTest < TestCaseClass
include FriendlyId::Test
class Journalist < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :simple_i18n
end
def setup
I18n.locale = :en
end
test "friendly_id should return the current locale's slug" do
journalist = Journ... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/sti_test.rb | test/sti_test.rb | require "helper"
class StiTest < TestCaseClass
include FriendlyId::Test
include FriendlyId::Test::Shared::Core
include FriendlyId::Test::Shared::Slugged
class Journalist < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: [:slugged]
end
class Editorialist < Journalist
end
def mode... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/candidates_test.rb | test/candidates_test.rb | require "helper"
class CandidatesTest < TestCaseClass
include FriendlyId::Test
class Airport
def initialize(code)
@code = code
end
attr_reader :code
alias_method :to_s, :code
end
class City < ActiveRecord::Base
extend FriendlyId
friendly_id :slug_candidates, use: :slugged
al... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/generator_test.rb | test/generator_test.rb | require "helper"
require "rails/generators"
require "generators/friendly_id_generator"
class FriendlyIdGeneratorTest < Rails::Generators::TestCase
tests FriendlyIdGenerator
destination File.expand_path("../../tmp", __FILE__)
setup :prepare_destination
test "should generate a migration" do
run_generator
... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/history_test.rb | test/history_test.rb | require "helper"
class HistoryTest < TestCaseClass
include FriendlyId::Test
include FriendlyId::Test::Shared::Core
class Manual < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: [:slugged, :history]
end
def model_class
Manual
end
test "should insert record in slugs table on cr... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/core_test.rb | test/core_test.rb | require "helper"
class Book < ActiveRecord::Base
extend FriendlyId
friendly_id :name
end
class Author < ActiveRecord::Base
extend FriendlyId
friendly_id :name
has_many :books
end
class CoreTest < TestCaseClass
include FriendlyId::Test
include FriendlyId::Test::Shared::Core
def model_class
Author... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/slugged_test.rb | test/slugged_test.rb | require "helper"
class Journalist < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
end
class Article < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
end
class Novelist < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged, sequence_separato... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/object_utils_test.rb | test/object_utils_test.rb | require "helper"
class ObjectUtilsTest < TestCaseClass
include FriendlyId::Test
test "strings with letters are friendly_ids" do
assert "a".friendly_id?
end
test "integers should be unfriendly ids" do
assert 1.unfriendly_id?
end
test "numeric strings are neither friendly nor unfriendly" do
as... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/sequentially_slugged_test.rb | test/sequentially_slugged_test.rb | require "helper"
class Article < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :sequentially_slugged
end
class SequentiallySluggedTest < TestCaseClass
include FriendlyId::Test
include FriendlyId::Test::Shared::Core
def model_class
Article
end
test "should generate numerically sequen... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/finders_test.rb | test/finders_test.rb | require "helper"
class JournalistWithFriendlyFinders < ActiveRecord::Base
self.table_name = "journalists"
extend FriendlyId
scope :existing, -> { where("1 = 1") }
friendly_id :name, use: [:slugged, :finders]
end
class Finders < TestCaseClass
include FriendlyId::Test
def model_class
JournalistWithFrie... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/numeric_slug_test.rb | test/numeric_slug_test.rb | require "helper"
class Article < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
end
class ArticleWithNumericPrevention < ActiveRecord::Base
self.table_name = "articles"
extend FriendlyId
friendly_id :name, use: :slugged
friendly_id_config.treat_numeric_as_conflict = true
end
class ... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/configuration_test.rb | test/configuration_test.rb | require "helper"
class ConfigurationTest < TestCaseClass
include FriendlyId::Test
def setup
@model_class = Class.new(ActiveRecord::Base) do
self.abstract_class = true
end
end
test "should set model class on initialization" do
config = FriendlyId::Configuration.new @model_class
assert_eq... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/helper.rb | test/helper.rb | require "bundler/setup"
if ENV["COVERALLS"] || ENV["COVERAGE"]
require "simplecov"
if ENV["COVERALLS"]
require "coveralls"
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
end
SimpleCov.start do
add_filter "test"
add_filter "friendly_id/migration"
end
end
begin
require "minitest"
resc... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/base_test.rb | test/base_test.rb | require "helper"
class CoreTest < TestCaseClass
include FriendlyId::Test
test "friendly_id can be added using 'extend'" do
klass = Class.new(ActiveRecord::Base) do
extend FriendlyId
end
assert klass.respond_to? :friendly_id
end
test "friendly_id can be added using 'include'" do
klass = ... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/reserved_test.rb | test/reserved_test.rb | require "helper"
class ReservedTest < TestCaseClass
include FriendlyId::Test
class Journalist < ActiveRecord::Base
extend FriendlyId
friendly_id :slug_candidates, use: [:slugged, :reserved], reserved_words: %w[new edit]
after_validation :move_friendly_id_error_to_name
def move_friendly_id_error_... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/schema.rb | test/schema.rb | require "friendly_id/migration"
module FriendlyId
module Test
migration_class =
if ActiveRecord::VERSION::MAJOR >= 5
ActiveRecord::Migration[4.2]
else
ActiveRecord::Migration
end
class Schema < migration_class
class << self
def down
CreateFriendlyIdS... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/shared.rb | test/shared.rb | module FriendlyId
module Test
module Shared
module Slugged
test "configuration should have a sequence_separator" do
assert !model_class.friendly_id_config.sequence_separator.empty?
end
test "should make a new slug if the slug has been set to nil changed" do
with_... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/scoped_test.rb | test/scoped_test.rb | require "helper"
class Novelist < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
end
class Novel < ActiveRecord::Base
extend FriendlyId
belongs_to :novelist
belongs_to :publisher
friendly_id :name, use: :scoped, scope: [:publisher, :novelist]
def should_generate_new_friendly_id?
... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/benchmarks/finders.rb | test/benchmarks/finders.rb | require File.expand_path("../../helper", __FILE__)
require "ffaker"
# This benchmark tests ActiveRecord and FriendlyId methods for performing a find
#
# ActiveRecord: where.first 8.970000 0.040000 9.010000 ( 9.029544)
# ActiveRecord: where.take 8.100000 0.030000 8.1300... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/test/benchmarks/object_utils.rb | test/benchmarks/object_utils.rb | require File.expand_path("../../helper", __FILE__)
# This benchmark compares the timings of the friendly_id? and unfriendly_id? on various objects
#
# integer friendly_id? 6.370000 0.000000 6.370000 ( 6.380925)
# integer unfriendly_id? 6.640000 0.010000 6.650000 ( 6.646057)
# AR::Base fri... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id.rb | lib/friendly_id.rb | require "active_record"
require "friendly_id/base"
require "friendly_id/object_utils"
require "friendly_id/configuration"
require "friendly_id/finder_methods"
# @guide begin
#
# ## About FriendlyId
#
# FriendlyId is an add-on to Ruby's Active Record that allows you to replace ids
# in your URLs with strings:
#
# #... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/sequentially_slugged.rb | lib/friendly_id/sequentially_slugged.rb | require_relative "sequentially_slugged/calculator"
module FriendlyId
module SequentiallySlugged
def self.setup(model_class)
model_class.friendly_id_config.use :slugged
end
def resolve_friendly_id_conflict(candidate_slugs)
candidate = candidate_slugs.first
return if candidate.nil?
... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/simple_i18n.rb | lib/friendly_id/simple_i18n.rb | require "i18n"
module FriendlyId
# @guide begin
#
# ## Translating Slugs Using Simple I18n
#
# The {FriendlyId::SimpleI18n SimpleI18n} module adds very basic i18n support to
# FriendlyId.
#
# In order to use this module, your model must have a slug column for each locale.
# By default FriendlyId look... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/version.rb | lib/friendly_id/version.rb | module FriendlyId
VERSION = "5.6.0".freeze
end
| ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/scoped.rb | lib/friendly_id/scoped.rb | require "friendly_id/slugged"
module FriendlyId
# @guide begin
#
# ## Unique Slugs by Scope
#
# The {FriendlyId::Scoped} module allows FriendlyId to generate unique slugs
# within a scope.
#
# This allows, for example, two restaurants in different cities to have the slug
# `joes-diner`:
#
# c... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/finders.rb | lib/friendly_id/finders.rb | module FriendlyId
# @guide begin
#
# ## Performing Finds with FriendlyId
#
# FriendlyId offers enhanced finders which will search for your record by
# friendly id, and fall back to the numeric id if necessary. This makes it easy
# to add FriendlyId to an existing application with minimal code modification... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/slug_generator.rb | lib/friendly_id/slug_generator.rb | module FriendlyId
# The default slug generator offers functionality to check slug candidates for
# availability.
class SlugGenerator
def initialize(scope, config)
@scope = scope
@config = config
end
def available?(slug)
if @config.uses?(::FriendlyId::Reserved) && @config.reserved_wo... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/initializer.rb | lib/friendly_id/initializer.rb | # FriendlyId Global Configuration
#
# Use this to set up shared configuration options for your entire application.
# Any of the configuration options shown here can also be applied to single
# models by passing arguments to the `friendly_id` class method or defining
# methods in your model.
#
# To learn more, check out... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/candidates.rb | lib/friendly_id/candidates.rb | require "securerandom"
module FriendlyId
# This class provides the slug candidate functionality.
# @see FriendlyId::Slugged
class Candidates
include Enumerable
def initialize(object, *array)
@object = object
@raw_candidates = to_candidate_array(object, array.flatten(1))
end
def each... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/slugged.rb | lib/friendly_id/slugged.rb | require "friendly_id/slug_generator"
require "friendly_id/candidates"
module FriendlyId
# @guide begin
#
# ## Slugged Models
#
# FriendlyId can use a separate column to store slugs for models which require
# some text processing.
#
# For example, blog applications typically use a post title to provide ... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/reserved.rb | lib/friendly_id/reserved.rb | module FriendlyId
# @guide begin
#
# ## Reserved Words
#
# The {FriendlyId::Reserved Reserved} module adds the ability to exclude a list of
# words from use as FriendlyId slugs.
#
# With Ruby on Rails, FriendlyId's generator generates an initializer that
# reserves some words such as "new" and "edit" ... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/slug.rb | lib/friendly_id/slug.rb | module FriendlyId
# A FriendlyId slug stored in an external table.
#
# @see FriendlyId::History
class Slug < ActiveRecord::Base
belongs_to :sluggable, polymorphic: true
def sluggable
sluggable_type.constantize.unscoped { super }
end
def to_param
slug
end
end
end
| ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/base.rb | lib/friendly_id/base.rb | module FriendlyId
# @guide begin
#
# ## Setting Up FriendlyId in Your Model
#
# To use FriendlyId in your ActiveRecord models, you must first either extend or
# include the FriendlyId module (it makes no difference), then invoke the
# {FriendlyId::Base#friendly_id friendly_id} method to configure your des... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/configuration.rb | lib/friendly_id/configuration.rb | module FriendlyId
# The configuration parameters passed to {Base#friendly_id} will be stored in
# this object.
class Configuration
attr_writer :base
# The default configuration options.
attr_reader :defaults
# The modules in use
attr_reader :modules
# The model class that this configura... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/finder_methods.rb | lib/friendly_id/finder_methods.rb | module FriendlyId
module FinderMethods
# Finds a record using the given id.
#
# If the id is "unfriendly", it will call the original find method.
# If the id is a numeric string like '123' it will first look for a friendly
# id matching '123' and then fall back to looking for a record with the
... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/object_utils.rb | lib/friendly_id/object_utils.rb | module FriendlyId
# Instances of these classes will never be considered a friendly id.
# @see FriendlyId::ObjectUtils#friendly_id
UNFRIENDLY_CLASSES = [
Array,
FalseClass,
Hash,
NilClass,
Numeric,
Symbol,
TrueClass
]
# Utility methods for determining whether any object is a friend... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/migration.rb | lib/friendly_id/migration.rb | MIGRATION_CLASS =
if ActiveRecord::VERSION::MAJOR >= 5
ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"]
else
ActiveRecord::Migration
end
class CreateFriendlyIdSlugs < MIGRATION_CLASS
def change
create_table :friendly_id_slugs do |t|
t.string :slug, nu... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/history.rb | lib/friendly_id/history.rb | module FriendlyId
# @guide begin
#
# ## History: Avoiding 404's When Slugs Change
#
# FriendlyId's {FriendlyId::History History} module adds the ability to store a
# log of a model's slugs, so that when its friendly id changes, it's still
# possible to perform finds by the old id.
#
# The primary use ... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/friendly_id/sequentially_slugged/calculator.rb | lib/friendly_id/sequentially_slugged/calculator.rb | module FriendlyId
module SequentiallySlugged
class Calculator
attr_accessor :scope, :slug, :slug_column, :sequence_separator
def initialize(scope, slug, slug_column, sequence_separator, base_class)
@scope = scope
@slug = slug
table_name = scope.connection.quote_table_name(base... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
norman/friendly_id | https://github.com/norman/friendly_id/blob/f72defb209de742fa51da7aedd1f01687f9e1d4d/lib/generators/friendly_id_generator.rb | lib/generators/friendly_id_generator.rb | require "rails/generators"
require "rails/generators/active_record"
# This generator adds a migration for the {FriendlyId::History
# FriendlyId::History} addon.
class FriendlyIdGenerator < ActiveRecord::Generators::Base
# ActiveRecord::Generators::Base inherits from Rails::Generators::NamedBase which requires a NAME... | ruby | MIT | f72defb209de742fa51da7aedd1f01687f9e1d4d | 2026-01-04T15:40:45.482615Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/features/steps/httparty_steps.rb | features/steps/httparty_steps.rb | When /^I set my HTTParty timeout option to (\d+)$/ do |timeout|
@request_options[:timeout] = timeout.to_i
end
When /^I set my HTTParty open_timeout option to (\d+)$/ do |timeout|
@request_options[:open_timeout] = timeout.to_i
end
When /^I set my HTTParty read_timeout option to (\d+)$/ do |timeout|
@request_opti... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/features/steps/env.rb | features/steps/env.rb | require 'mongrel'
require './lib/httparty'
require 'rspec/expectations'
require 'aruba/cucumber'
def run_server(port)
@host_and_port = "0.0.0.0:#{port}"
@server = Mongrel::HttpServer.new("0.0.0.0", port)
@server.run
@request_options = {}
end
def new_port
server = TCPServer.new('0.0.0.0', nil)
port = serve... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/features/steps/mongrel_helper.rb | features/steps/mongrel_helper.rb | require 'base64'
class BasicMongrelHandler < Mongrel::HttpHandler
attr_accessor :content_type, :custom_headers, :response_body, :response_code, :preprocessor, :username, :password
def initialize
@content_type = "text/html"
@response_body = ""
@response_code = 200
@custom_headers = {}
end
def p... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/features/steps/httparty_response_steps.rb | features/steps/httparty_response_steps.rb | # Not needed anymore in ruby 2.0, but needed to resolve constants
# in nested namespaces. This is taken from rails :)
def constantize(camel_cased_word)
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
constant = Object
names.each do |name|
constant = constant.const_def... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/features/steps/remote_service_steps.rb | features/steps/remote_service_steps.rb | Given /a remote service that returns '(.*)'/ do |response_body|
@handler = BasicMongrelHandler.new
step "the response from the service has a body of '#{response_body}'"
end
Given /^a remote service that returns:$/ do |response_body|
@handler = BasicMongrelHandler.new
@handler.response_body = response_body
end
... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty_spec.rb | spec/httparty_spec.rb | require_relative 'spec_helper'
RSpec.describe HTTParty do
before(:each) do
@klass = Class.new
@klass.instance_eval { include HTTParty }
end
describe "pem" do
it 'should set the pem content' do
@klass.pem 'PEM-CONTENT'
expect(@klass.default_options[:pem]).to eq('PEM-CONTENT')
end
... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | true |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/spec_helper.rb | spec/spec_helper.rb | require "simplecov"
SimpleCov.start
require "httparty"
require 'webmock/rspec'
def file_fixture(filename)
open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename}")).read
end
Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each {|f| require f}
RSpec.configure do |config|
... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/support/ssl_test_helper.rb | spec/support/ssl_test_helper.rb | require 'pathname'
module HTTParty
module SSLTestHelper
def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {}, &block)
options = {
format: :json,
timeout: 30
}.merge(options)
if mode
ca_path = File.expand_path("../../fixtures/ssl/generated/#{ca_base... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/support/stub_response.rb | spec/support/stub_response.rb | module HTTParty
module StubResponse
def stub_http_response_with(filename)
format = filename.split('.').last.intern
data = file_fixture(filename)
response = Net::HTTPOK.new("1.1", 200, "Content for you")
allow(response).to receive(:body).and_return(data)
http_request = HTTParty::Req... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/support/ssl_test_server.rb | spec/support/ssl_test_server.rb | require 'openssl'
require 'socket'
require 'thread'
# NOTE: This code is garbage. It probably has deadlocks, it might leak
# threads, and otherwise cause problems in a real system. It's really only
# intended for testing HTTParty.
class SSLTestServer
attr_accessor :ctx # SSLContext object
attr_reader :port
... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/response_spec.rb | spec/httparty/response_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::Response do
before do
@last_modified = Date.new(2010, 1, 15).to_s
@content_length = '1024'
@request_object = HTTParty::Request.new Net::HTTP::Get, '/'
@response_object = Net::HTTPOK.new('1.1', 200, 'OK')
allow(@response_object).to receive_messages(bo... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/headers_processor_spec.rb | spec/httparty/headers_processor_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::HeadersProcessor do
subject(:headers) { options[:headers] }
let(:options) { { headers: {} } }
let(:global_headers) { {} }
before { described_class.new(global_headers, options).call }
context 'when headers are not set at all' do
it 'returns empty hash' do
... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/exception_spec.rb | spec/httparty/exception_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::Error do
subject { described_class }
describe '#ancestors' do
subject { super().ancestors }
it { is_expected.to include(StandardError) }
end
describe HTTParty::UnsupportedFormat do
describe '#ancestors' do
subject { super().ancestors }
it... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/request_spec.rb | spec/httparty/request_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::Request do
before do
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', format: :xml)
end
describe "::NON_RAILS_QUERY_STRING_NORMALIZER" do
let(:normalizer) { HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER }
it "doesn't mod... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | true |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/hash_conversions_spec.rb | spec/httparty/hash_conversions_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::HashConversions do
describe ".to_params" do
it "creates a params string from a hash" do
hash = {
name: "bob",
address: {
street: '111 ruby ave.',
city: 'ruby central',
phones: ['111-111-1111', '222-222-2222']
... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/decompressor_spec.rb | spec/httparty/decompressor_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::Decompressor do
describe '.SupportedEncodings' do
it 'returns a hash' do
expect(HTTParty::Decompressor::SupportedEncodings).to be_instance_of(Hash)
end
end
describe '#decompress' do
let(:body) { 'body' }
let(:encoding) { 'none' }
let(:deco... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/ssl_spec.rb | spec/httparty/ssl_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::Request do
context "SSL certificate verification" do
before do
WebMock.disable!
end
after do
WebMock.enable!
end
it "should fail when no trusted CA list is specified, by default" do
expect do
ssl_verify_test(nil, nil, "sel... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/parser_spec.rb | spec/httparty/parser_spec.rb | require 'spec_helper'
require 'multi_xml'
RSpec.describe HTTParty::Parser do
describe ".SupportedFormats" do
it "returns a hash" do
expect(HTTParty::Parser::SupportedFormats).to be_instance_of(Hash)
end
end
describe ".call" do
it "generates an HTTParty::Parser instance with the given body and ... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/cookie_hash_spec.rb | spec/httparty/cookie_hash_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::CookieHash do
before(:each) do
@cookie_hash = HTTParty::CookieHash.new
end
describe "#add_cookies" do
describe "with a hash" do
it "should add new key/value pairs to the hash" do
@cookie_hash.add_cookies(foo: "bar")
@cookie_hash.add_co... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/net_digest_auth_spec.rb | spec/httparty/net_digest_auth_spec.rb | require 'spec_helper'
RSpec.describe Net::HTTPHeader::DigestAuthenticator do
def setup_digest(response)
digest = Net::HTTPHeader::DigestAuthenticator.new("Mufasa",
"Circle Of Life", "GET", "/dir/index.html", response)
allow(digest).to receive(:random).and... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/response_fragment_spec.rb | spec/httparty/response_fragment_spec.rb | require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
RSpec.describe HTTParty::ResponseFragment do
it "access to fragment" do
fragment = HTTParty::ResponseFragment.new("chunk", nil, nil)
expect(fragment).to eq("chunk")
end
it "has access to delegators" do
response = double(co... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/connection_adapter_spec.rb | spec/httparty/connection_adapter_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::ConnectionAdapter do
describe "initialization" do
let(:uri) { URI 'http://www.google.com' }
it "takes a URI as input" do
HTTParty::ConnectionAdapter.new(uri)
end
it "raises an ArgumentError if the uri is nil" do
expect { HTTParty::Connection... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/logger/curl_formatter_spec.rb | spec/httparty/logger/curl_formatter_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::Logger::CurlFormatter do
describe "#format" do
let(:logger) { double('Logger') }
let(:response_object) { Net::HTTPOK.new('1.1', 200, 'OK') }
let(:parsed_response) { lambda { {"foo" => "bar"} } }
let(:response) do
HTTParty::Response.new(re... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/logger/apache_formatter_spec.rb | spec/httparty/logger/apache_formatter_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::Logger::ApacheFormatter do
let(:subject) { described_class.new(logger_double, :info) }
let(:logger_double) { double('Logger') }
let(:request_double) { double('Request', http_method: Net::HTTP::Get, path: "http://my.domain.com/my_path") }
let(:request_time) { Time.... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/logger/logger_spec.rb | spec/httparty/logger/logger_spec.rb | require 'spec_helper'
RSpec.describe HTTParty::Logger do
describe ".build" do
subject { HTTParty::Logger }
it "defaults level to :info" do
logger_double = double
expect(subject.build(logger_double, nil, nil).level).to eq(:info)
end
it "defaults format to :apache" do
logger_double ... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/logger/logstash_formatter_spec.rb | spec/httparty/logger/logstash_formatter_spec.rb | require 'json'
require 'spec_helper'
RSpec.describe HTTParty::Logger::LogstashFormatter do
let(:severity) { :info }
let(:http_method) { 'GET' }
let(:path) { 'http://my.domain.com/my_path' }
let(:logger_double) { double('Logger') }
let(:request_double) { double('Request', http_method: Net::HTTP::Get, path: "#... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/request/streaming_multipart_body_spec.rb | spec/httparty/request/streaming_multipart_body_spec.rb | require 'spec_helper'
require 'tempfile'
RSpec.describe HTTParty::Request::StreamingMultipartBody do
let(:boundary) { '------------------------c772861a5109d5ef' }
describe '#read' do
context 'with a simple file' do
let(:file) { File.open('spec/fixtures/tiny.gif', 'rb') }
let(:parts) { [['avatar', ... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/spec/httparty/request/body_spec.rb | spec/httparty/request/body_spec.rb | require 'spec_helper'
require 'tempfile'
RSpec.describe HTTParty::Request::Body do
describe '#call' do
let(:options) { {} }
subject { described_class.new(params, **options).call }
context 'when params is string' do
let(:params) { 'name=Bob%20Jones' }
it { is_expected.to eq params }
end... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/rubyurl.rb | examples/rubyurl.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class Rubyurl
include HTTParty
base_uri 'rubyurl.com'
def self.shorten(website_url)
post('/api/links.json', query: { link: { website_url: website_url } })
end
end
pp Rubyurl.shorten('htt... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/custom_parsers.rb | examples/custom_parsers.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class ParseAtom
include HTTParty
# Support Atom along with the default parsers: xml, json, etc.
class Parser::Atom < HTTParty::Parser
SupportedFormats.merge!({"application/atom+xml" => :ato... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/logging.rb | examples/logging.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'logger'
require 'pp'
my_logger = Logger.new STDOUT
my_logger.info "Logging can be used on the main HTTParty class. It logs redirects too."
HTTParty.get "http://google.com", logger: my_logger
my_logger.i... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/headers_and_user_agents.rb | examples/headers_and_user_agents.rb | # To send custom user agents to identify your application to a web service (or mask as a specific browser for testing), send "User-Agent" as a hash to headers as shown below.
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
response = HTTParty.get(... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/microsoft_graph.rb | examples/microsoft_graph.rb | require 'httparty'
class MicrosoftGraph
MS_BASE_URL = "https://login.microsoftonline.com".freeze
TOKEN_REQUEST_PATH = "oauth2/v2.0/token".freeze
def initialize(tenant_id)
@tenant_id = tenant_id
end
# Make a request to the Microsoft Graph API, for instance https://graph.microsoft.com/v1.0/users
def re... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/party_foul_mode.rb | examples/party_foul_mode.rb | require 'httparty'
class APIClient
include HTTParty
base_uri 'api.example.com'
def self.fetch_user(id)
begin
get("/users/#{id}", foul: true)
rescue HTTParty::NetworkError => e
handle_network_error(e)
rescue HTTParty::ResponseError => e
handle_api_error(e)
end
end
private
... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/twitter.rb | examples/twitter.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
config = YAML.load(File.read(File.join(ENV['HOME'], '.twitter')))
class Twitter
include HTTParty
base_uri 'twitter.com'
def initialize(u, p)
@auth = {username: u, password: p}
end
# wh... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/peer_cert.rb | examples/peer_cert.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
peer_cert = nil
HTTParty.get("https://www.example.com") do |fragment|
peer_cert ||= fragment.connection.peer_cert
end
puts "The server's certificate expires #{peer_cert.not_after}"
| ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/google.rb | examples/google.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class Google
include HTTParty
format :html
end
# google.com redirects to www.google.com so this is live test for redirection
pp Google.get('http://google.com')
puts '', '*' * 70, ''
# check tha... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/basic.rb | examples/basic.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
# You can also use post, put, delete, head, options in the same fashion
response = HTTParty.get('https://api.stackexchange.com/2.2/questions?site=stackoverflow')
puts response.body, response.code, res... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/stream_download.rb | examples/stream_download.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
# download file linux-4.6.4.tar.xz without using the memory
response = nil
filename = "linux-4.6.4.tar.xz"
url = "https://cdn.kernel.org/pub/linux/kernel/v4.x/#{filename}"
File.open(filename, "w") do... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/whoismyrep.rb | examples/whoismyrep.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class Rep
include HTTParty
end
pp Rep.get('http://whoismyrepresentative.com/getall_mems.php?zip=46544')
pp Rep.get('http://whoismyrepresentative.com/getall_mems.php', query: { zip: 46544 })
| ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/tripit_sign_in.rb | examples/tripit_sign_in.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
class TripIt
include HTTParty
base_uri 'https://www.tripit.com'
debug_output
def initialize(email, password)
@email = email
get_response = self.class.get('/account/login')
get_response_cookie ... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/crack.rb | examples/crack.rb | require 'rubygems'
require 'crack'
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class Rep
include HTTParty
parser(
proc do |body, format|
Crack::XML.parse(body)
end
)
end
pp Rep.get('http://whoismyrepresentative.com/getall... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/aaws.rb | examples/aaws.rb | require 'rubygems'
require 'active_support'
require 'active_support/core_ext/hash'
require 'active_support/core_ext/string'
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
config = YAML.load(File.read(File.join(ENV['HOME'], '.aaws')))
module AAWS
... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/rescue_json.rb | examples/rescue_json.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
# Take note of the "; 1" at the end of the following line. It's required only if
# running this in IRB, because IRB will try to inspect the variable named
# "request", triggering the exception.
request = HTTParty.... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/body_stream.rb | examples/body_stream.rb | # To upload file to a server use :body_stream
HTTParty.put(
'http://localhost:3000/train',
body_stream: File.open('sample_configs/config_train_server_md.yml', 'r')
)
# Actually, it works with any IO object
HTTParty.put(
'http://localhost:3000/train',
body_stream: StringIO.new('foo')
)
| ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/stackexchange.rb | examples/stackexchange.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class StackExchange
include HTTParty
base_uri 'api.stackexchange.com'
def initialize(service, page)
@options = { query: { site: service, page: page } }
end
def questions
self.class... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/idn.rb | examples/idn.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class Idn
include HTTParty
uri_adapter Addressable::URI
end
pp Idn.get("https://i❤️.ws/emojidomain/💎?format=json") | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/delicious.rb | examples/delicious.rb | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
config = YAML.load(File.read(File.join(ENV['HOME'], '.delicious')))
class Delicious
include HTTParty
base_uri 'https://api.del.icio.us/v1'
def initialize(u, p)
@auth = { username: u, passwo... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/multipart.rb | examples/multipart.rb | # If you are uploading file in params, multipart will used as content-type automatically
HTTParty.post(
'http://localhost:3000/user',
body: {
name: 'Foo Bar',
email: 'example@email.com',
avatar: File.open('/full/path/to/avatar.jpg')
}
)
# However, you can force it yourself
HTTParty.post(
'http:/... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/examples/nokogiri_html_parser.rb | examples/nokogiri_html_parser.rb | require 'rubygems'
require 'nokogiri'
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class HtmlParserIncluded < HTTParty::Parser
def html
Nokogiri::HTML(body)
end
end
class Page
include HTTParty
parser HtmlParserIncluded
end
pp Page... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
jnunemaker/httparty | https://github.com/jnunemaker/httparty/blob/55ec76e8d1df7903eab3f7c2367991400d3cf65e/lib/httparty.rb | lib/httparty.rb | # frozen_string_literal: true
require 'pathname'
require 'net/http'
require 'uri'
require 'httparty/module_inheritable_attributes'
require 'httparty/cookie_hash'
require 'httparty/net_digest_auth'
require 'httparty/version'
require 'httparty/connection_adapter'
require 'httparty/logger/logger'
require 'httparty/reque... | ruby | MIT | 55ec76e8d1df7903eab3f7c2367991400d3cf65e | 2026-01-04T15:41:22.900579Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.