source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
sferik/twitter-ruby
https://github.com/sferik/twitter-ruby
test/twitter/rest/search_test.rb
Ruby
mit
4,577
master
2,040
require "test_helper" describe Twitter::REST::Search do before do @client = build_rest_client end describe "#search" do it "does not mutate the options hash passed by the caller" do options = {} stub_get("/1.1/search/tweets.json").with(query: {q: "#freebandnames", count: "100"}).to_return(bo...
github
sferik/twitter-ruby
https://github.com/sferik/twitter-ruby
test/twitter/rest/client_test.rb
Ruby
mit
4,577
master
1,965
require "test_helper" describe Twitter::REST::Client do before do @client = build_rest_client end describe "#bearer_token?" do it "returns true if the app token is present" do client = Twitter::REST::Client.new(consumer_key: "CK", consumer_secret: "CS", bearer_token: "BT") assert_predicate(...
github
sferik/twitter-ruby
https://github.com/sferik/twitter-ruby
test/twitter/rest/undocumented_test.rb
Ruby
mit
4,577
master
6,662
require "test_helper" describe Twitter::REST::Undocumented do before do @client = build_rest_client end describe "#following_followers_of" do describe "with a screen_name passed" do before do stub_get("/users/following_followers_of.json").with(query: {screen_name: "sferik", cursor: "-1"})....
github
sferik/twitter-ruby
https://github.com/sferik/twitter-ruby
test/twitter/rest/lists_test.rb
Ruby
mit
4,577
master
56,584
require "test_helper" describe Twitter::REST::Lists do before do @client = build_rest_client end describe "private path parsing helpers" do describe "#merge_slug_and_owner!" do it "extracts owner_screen_name as a string when owner and slug are in the path" do hash = {} @client.sen...
github
sferik/twitter-ruby
https://github.com/sferik/twitter-ruby
test/twitter/rest/saved_searches_test.rb
Ruby
mit
4,577
master
6,594
require "test_helper" describe Twitter::REST::SavedSearches do before do @client = build_rest_client end describe "#saved_searches" do describe "with ids passed" do before do stub_get("/1.1/saved_searches/show/16129012.json").to_return(body: fixture("saved_search.json"), headers: json_head...
github
sferik/twitter-ruby
https://github.com/sferik/twitter-ruby
test/twitter/rest/utils_test.rb
Ruby
mit
4,577
master
10,751
require "test_helper" describe "Twitter::REST::Utils helper behavior" do let(:client_class) do Class.new do include Twitter::REST::Utils attr_accessor :credentials_id def verify_credentials(skip_status:) raise ArgumentError, "skip_status must be true" unless skip_status Struc...
github
sferik/twitter-ruby
https://github.com/sferik/twitter-ruby
test/twitter/rest/help_test.rb
Ruby
mit
4,577
master
3,231
require "test_helper" describe Twitter::REST::Help do before do @client = build_rest_client end describe "#languages" do before do stub_get("/1.1/help/languages.json").to_return(body: fixture("languages.json"), headers: json_headers) end it "requests the correct resource" do @client...
github
sferik/twitter-ruby
https://github.com/sferik/twitter-ruby
test/twitter/rest/direct_messages/welcome_messages_test.rb
Ruby
mit
4,577
master
17,679
require "test_helper" describe Twitter::REST::DirectMessages::WelcomeMessages do before do @client = build_rest_client @client.define_singleton_method(:user_id) { 22_095_868 } end describe "Welcome Messages" do describe "#create_welcome_message" do before do stub_post("/1.1/direct_mess...
github
sferik/twitter-ruby
https://github.com/sferik/twitter-ruby
test/twitter/geo/polygon_test.rb
Ruby
mit
4,577
master
1,278
require "test_helper" describe Twitter::Geo::Polygon do before do @polygon = Twitter::Geo::Polygon.new(coordinates: [[[-122.40348192, 37.77752898], [-122.387436, 37.77752898], [-122.387436, 37.79448597], [-122.40348192, 37.79448597]]]) end describe "#==" do it "returns true for empty objects" do p...
github
sferik/twitter-ruby
https://github.com/sferik/twitter-ruby
test/twitter/geo/point_test.rb
Ruby
mit
4,577
master
2,336
require "test_helper" describe Twitter::Geo::Point do before do @point = Twitter::Geo::Point.new(coordinates: [-122.399983, 37.788299]) end describe "#==" do it "returns true for empty objects" do point = Twitter::Geo::Point.new other = Twitter::Geo::Point.new assert_equal(point, othe...
github
github/gemoji
https://github.com/github/gemoji
Rakefile
Ruby
mit
4,509
master
585
require 'rake/testtask' task :default => :test Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList["test/*_test.rb"] end namespace :db do desc %(Generate Emoji data files needed for development) task :generate => [ 'vendor/unicode-emoji-test.txt', ] desc %(Dump a list of supported Emo...
github
github/gemoji
https://github.com/github/gemoji
gemoji.gemspec
Ruby
mit
4,509
master
458
Gem::Specification.new do |s| s.name = "gemoji" s.version = "4.1.0" s.summary = "Unicode emoji library" s.description = "Character information and metadata for Unicode emoji." s.required_ruby_version = '> 1.9' s.authors = ["GitHub"] s.email = "support@github.com" s.homepage = "https://github.co...
github
github/gemoji
https://github.com/github/gemoji
lib/emoji.rb
Ruby
mit
4,509
master
4,160
# encoding: utf-8 # frozen_string_literal: true require 'emoji/character' require 'json' module Emoji extend self def data_file File.expand_path('../../db/emoji.json', __FILE__) end def all return @all if defined? @all @all = [] parse_data_file @all end # Public: Initialize an Emoji...
github
github/gemoji
https://github.com/github/gemoji
lib/emoji/character.rb
Ruby
mit
4,509
master
3,614
# frozen_string_literal: true module Emoji class Character # Inspect individual Unicode characters in a string by dumping its # codepoints in hexadecimal format. def self.hex_inspect(str) str.codepoints.map { |c| c.to_s(16).rjust(4, '0') }.join('-') end # True if the emoji is not a standar...
github
github/gemoji
https://github.com/github/gemoji
db/dump.rb
Ruby
mit
4,509
master
1,940
# frozen_string_literal: true require "i18n" require 'emoji' require 'json' require_relative './emoji-test-parser' I18n.config.available_locales = :en items = [] _, categories = EmojiTestParser.parse(File.expand_path("../../vendor/unicode-emoji-test.txt", __FILE__)) seen_existing = {} for category in categories f...
github
github/gemoji
https://github.com/github/gemoji
db/emoji-test-parser.rb
Ruby
mit
4,509
master
3,194
# frozen_string_literal: true module EmojiTestParser VARIATION_SELECTOR_16 = "\u{fe0f}" SKIN_TONES = [ "\u{1F3FB}", # light skin tone "\u{1F3FC}", # medium-light skin tone "\u{1F3FD}", # medium skin tone "\u{1F3FE}", # medium-dark skin tone "\u{1F3FF}", # dark skin tone ] SKIN_TONES_RE = /(...
github
github/gemoji
https://github.com/github/gemoji
test/documentation_test.rb
Ruby
mit
4,509
master
1,330
require 'test_helper' # Pull the EmojiHelper example from the docs readme = File.expand_path('../../README.md', __FILE__) docs = File.open(readme, 'r:UTF-8') { |f| f.read } eval docs.match(/^module.+?^end/m)[0] String.class_eval do def html_safe() self end def present?() !empty? end end class DocumentationTest <...
github
github/gemoji
https://github.com/github/gemoji
test/emoji_test.rb
Ruby
mit
4,509
master
8,118
require 'test_helper' require_relative '../db/emoji-test-parser' class EmojiTest < TestCase test "fetching all emoji" do count = Emoji.all.size assert count > 845, "there were too few emojis: #{count}" end test "unicodes set contains the unicodes" do min_size = Emoji.all.size count = Emoji.all.m...
github
ankane/ahoy
https://github.com/ankane/ahoy
Rakefile
Ruby
mit
4,446
master
201
require "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new do |t| t.pattern = "test/*_test.rb" t.warning = false # for bson, mongoid, device_detector, browser end task default: :test
github
ankane/ahoy
https://github.com/ankane/ahoy
ahoy_matey.gemspec
Ruby
mit
4,446
master
704
require_relative "lib/ahoy/version" Gem::Specification.new do |spec| spec.name = "ahoy_matey" spec.version = Ahoy::VERSION spec.summary = "Simple, powerful, first-party analytics for Rails" spec.homepage = "https://github.com/ankane/ahoy" spec.license = "MIT" spec.author ...
github
ankane/ahoy
https://github.com/ankane/ahoy
Gemfile
Ruby
mit
4,446
master
385
source "https://rubygems.org" gemspec gem "rake" gem "minitest" gem "rails", "~> 8.1.0" gem "combustion" gem "browser", "~> 2.0" gem "user_agent_parser" gem "sqlite3", platform: :ruby gem "pg", platform: :ruby gem "mysql2", platform: :ruby gem "trilogy", platform: :ruby gem "mongoid", platform: :ruby gem "ostruct", p...
github
ankane/ahoy
https://github.com/ankane/ahoy
config/routes.rb
Ruby
mit
4,446
master
224
Rails.application.routes.draw do mount Ahoy::Engine => "/ahoy" if Ahoy.api end Ahoy::Engine.routes.draw do scope module: "ahoy" do resources :visits, only: [:create] resources :events, only: [:create] end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/base_generator_test.rb
Ruby
mit
4,446
master
352
require_relative "test_helper" require "generators/ahoy/base_generator" class BaseGeneratorTest < Rails::Generators::TestCase tests Ahoy::Generators::BaseGenerator destination File.expand_path("../tmp", __dir__) setup :prepare_destination def test_works run_generator assert_file "config/initializers/...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/query_methods_test.rb
Ruby
mit
4,446
master
492
require_relative "test_helper" case ENV["ADAPTER"] when "mysql2", "trilogy" require_relative "query_methods/mysql_json_test" require_relative "query_methods/mysql_text_test" when "postgresql" require_relative "query_methods/postgresql_hstore_test" require_relative "query_methods/postgresql_json_test" require...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/api_test.rb
Ruby
mit
4,446
master
5,074
require_relative "test_helper" class ApiTest < ActionDispatch::IntegrationTest include Rails.application.routes.mounted_helpers def setup Ahoy::Visit.delete_all Ahoy::Event.delete_all end def test_visit visit_token = random_token visitor_token = random_token post ahoy_engine.visits_url, ...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/geocode_test.rb
Ruby
mit
4,446
master
2,212
require_relative "test_helper" module Geocoder Result = Struct.new(:country, :state, :city, :latitude, :longitude, keyword_init: true) def self.search(ip) [Result.new( country: "Country", state: "Region", city: "City", latitude: 1, longitude: 2 )] end end class GeocodeTest...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/visitable_test.rb
Ruby
mit
4,446
master
216
require_relative "test_helper" class VisitableTest < ActionDispatch::IntegrationTest def test_visitable post products_url visit = Ahoy::Visit.last assert_equal visit, Product.last.ahoy_visit end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/exclude_test.rb
Ruby
mit
4,446
master
1,914
require_relative "test_helper" class ExcludeTest < ActionDispatch::IntegrationTest def test_track_bots_true with_options(track_bots: true) do get products_url, headers: {"User-Agent" => bot_user_agent} assert_equal 1, Ahoy::Visit.count end end def test_track_bots_false with_options(track...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/user_test.rb
Ruby
mit
4,446
master
1,155
require_relative "test_helper" class UserTest < ActionDispatch::IntegrationTest def test_user User.create!(name: "Test User") get products_url visit = Ahoy::Visit.last assert_equal "Test User", visit.user.name end def test_user_method_symbol with_options(user_method: :true_user) do get...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/visit_properties_test.rb
Ruby
mit
4,446
master
1,817
require_relative "test_helper" class VisitPropertiesTest < ActionDispatch::IntegrationTest def test_standard referrer = "http://www.example.com" get products_url, headers: {"Referer" => referrer} visit = Ahoy::Visit.last assert_equal referrer, visit.referrer assert_equal "www.example.com", visit...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/cookies_test.rb
Ruby
mit
4,446
master
1,713
require_relative "test_helper" class CookiesTest < ActionDispatch::IntegrationTest def test_cookies_true get products_url assert_equal ["ahoy_visit", "ahoy_visitor"], response.cookies.keys.sort end def test_cookies_false error = assert_raises do Ahoy.cookies = false end assert_match "T...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/test_helper.rb
Ruby
mit
4,446
master
1,817
require "bundler/setup" require "combustion" Bundler.require(:default) require "minitest/autorun" ENV["ADAPTER"] ||= "sqlite3" puts "Using #{ENV["ADAPTER"]}" logger = ActiveSupport::Logger.new(ENV["VERBOSE"] ? STDOUT : nil) frameworks = [:action_controller, :active_job] if ENV["ADAPTER"] == "mongoid" require_rela...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/mongoid_generator_test.rb
Ruby
mit
4,446
master
493
require_relative "test_helper" require "generators/ahoy/mongoid_generator" class MongoidGeneratorTest < Rails::Generators::TestCase tests Ahoy::Generators::MongoidGenerator destination File.expand_path("../tmp", __dir__) setup :prepare_destination def test_works run_generator assert_file "config/init...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/controller_test.rb
Ruby
mit
4,446
master
4,170
require_relative "test_helper" class ControllerTest < ActionDispatch::IntegrationTest def test_works get products_url assert_response :success assert_equal 1, Ahoy::Visit.count assert_equal 1, Ahoy::Event.count event = Ahoy::Event.last assert_equal "Viewed products", event.name assert_e...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/tracker_test.rb
Ruby
mit
4,446
master
1,742
require_relative "test_helper" class TrackerTest < Minitest::Test def test_no_request ahoy = Ahoy::Tracker.new ahoy.track("Some event", some_prop: true) event = Ahoy::Event.last assert_equal "Some event", event.name assert_equal({"some_prop" => true}, event.properties) assert_nil event.user_...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/activerecord_generator_test.rb
Ruby
mit
4,446
master
1,186
require_relative "test_helper" require "generators/ahoy/activerecord_generator" class ActiverecordGeneratorTest < Rails::Generators::TestCase tests Ahoy::Generators::ActiverecordGenerator destination File.expand_path("../tmp", __dir__) setup :prepare_destination def setup skip if ENV["ADAPTER"] == "mongo...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/internal/db/schema.rb
Ruby
mit
4,446
master
1,306
ActiveRecord::Schema.define do create_table :ahoy_visits do |t| t.string :visit_token t.string :visitor_token # the rest are recommended but optional # simply remove any you don't want # user t.references :user # standard t.string :ip t.text :user_agent t.text :referrer ...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/internal/app/controllers/products_controller.rb
Ruby
mit
4,446
master
510
class ProductsController < ApplicationController skip_before_action :track_ahoy_visit, only: [:no_visit] def index ahoy.track "Viewed products" head :ok end def list head :ok end def create Product.create! head :ok end def authenticate ahoy.authenticate(User.last) head :o...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/internal/app/models/ahoy/event.rb
Ruby
mit
4,446
master
200
class Ahoy::Event < ApplicationRecord include Ahoy::QueryMethods self.table_name = "ahoy_events" belongs_to :visit belongs_to :user, optional: true serialize :properties, coder: JSON end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/internal/config/routes.rb
Ruby
mit
4,446
master
258
Rails.application.routes.draw do resources :products, only: [:index, :create] do get :list, on: :collection get :authenticate, on: :collection get :no_visit, on: :collection end get "up" => "rails/health#show", as: :rails_health_check end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/query_methods/postgresql_text_test.rb
Ruby
mit
4,446
master
242
require_relative "query_methods_helper" class PostgresqlTextEvent < PostgresqlBase serialize :properties, coder: JSON end class PostgresqlTextTest < Minitest::Test include QueryMethodsTest def model PostgresqlTextEvent end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/query_methods/mysql_json_test.rb
Ruby
mit
4,446
master
262
require_relative "query_methods_helper" class MysqlJsonEvent < MysqlBase if connection.send(:mariadb?) serialize :properties, coder: JSON end end class MysqlJsonTest < Minitest::Test include QueryMethodsTest def model MysqlJsonEvent end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/query_methods/postgresql_jsonb_test.rb
Ruby
mit
4,446
master
208
require_relative "query_methods_helper" class PostgresqlJsonbEvent < PostgresqlBase end class PostgresqlJsonbTest < Minitest::Test include QueryMethodsTest def model PostgresqlJsonbEvent end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/query_methods/postgresql_json_test.rb
Ruby
mit
4,446
master
205
require_relative "query_methods_helper" class PostgresqlJsonEvent < PostgresqlBase end class PostgresqlJsonTest < Minitest::Test include QueryMethodsTest def model PostgresqlJsonEvent end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/query_methods/mongoid_test.rb
Ruby
mit
4,446
master
285
require_relative "query_methods_helper" class MongoidEvent include Mongoid::Document include Ahoy::QueryMethods field :name, type: String field :properties, type: Hash end class MongoidTest < Minitest::Test include QueryMethodsTest def model MongoidEvent end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/query_methods/mysql_text_test.rb
Ruby
mit
4,446
master
222
require_relative "query_methods_helper" class MysqlTextEvent < MysqlBase serialize :properties, coder: JSON end class MysqlTextTest < Minitest::Test include QueryMethodsTest def model MysqlTextEvent end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/query_methods/query_methods_helper.rb
Ruby
mit
4,446
master
332
require_relative "../test_helper" case ENV["ADAPTER"] when "mysql2", "trilogy" require_relative "../support/mysql" when "postgresql" require_relative "../support/postgresql" when "mongoid" require_relative "../support/mongoid" else require_relative "../support/sqlite" end require_relative "../support/query_me...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/query_methods/sqlite_text_test.rb
Ruby
mit
4,446
master
261
require_relative "query_methods_helper" class SqliteTextEvent < SqliteBase self.table_name = "text_events" serialize :properties, coder: JSON end class SqliteTextTest < Minitest::Test include QueryMethodsTest def model SqliteTextEvent end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/query_methods/postgresql_hstore_test.rb
Ruby
mit
4,446
master
211
require_relative "query_methods_helper" class PostgresqlHstoreEvent < PostgresqlBase end class PostgresqlHstoreTest < Minitest::Test include QueryMethodsTest def model PostgresqlHstoreEvent end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/support/postgresql.rb
Ruby
mit
4,446
master
643
ActiveRecord::Schema.define do enable_extension "hstore" create_table :postgresql_hstore_events, force: true do |t| t.string :name t.hstore :properties end create_table :postgresql_json_events, force: true do |t| t.string :name t.json :properties end create_table :postgresql_jsonb_events,...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/support/sqlite.rb
Ruby
mit
4,446
master
232
ActiveRecord::Schema.define do create_table :text_events, force: true do |t| t.string :name t.text :properties end end class SqliteBase < ActiveRecord::Base include Ahoy::QueryMethods self.abstract_class = true end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/support/mysql.rb
Ruby
mit
4,446
master
340
ActiveRecord::Schema.define do create_table :mysql_text_events, force: true do |t| t.string :name t.text :properties end create_table :mysql_json_events, force: true do |t| t.string :name t.json :properties end end class MysqlBase < ActiveRecord::Base include Ahoy::QueryMethods self.abstra...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/support/query_methods_test.rb
Ruby
mit
4,446
master
5,164
module QueryMethodsTest def setup model.delete_all end def test_empty assert_equal 0, count_events({}) end def test_string create_event value: "world" assert_equal 1, count_events(value: "world") end def test_number create_event value: 1 assert_equal 1, count_events(value: 1) ...
github
ankane/ahoy
https://github.com/ankane/ahoy
test/support/mongoid_models/product.rb
Ruby
mit
4,446
master
215
class Product include Mongoid::Document field :name, type: String visitable :ahoy_visit after_create :track_create def track_create Ahoy.instance.track("Created product", product_id: id) end end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/support/mongoid_models/ahoy/event.rb
Ruby
mit
4,446
master
303
class Ahoy::Event include Mongoid::Document # associations belongs_to :visit, class_name: "Ahoy::Visit", index: true belongs_to :user, index: true, optional: true # fields field :name, type: String field :properties, type: Hash field :time, type: Time index({name: 1, time: 1}) end
github
ankane/ahoy
https://github.com/ankane/ahoy
test/support/mongoid_models/ahoy/visit.rb
Ruby
mit
4,446
master
1,220
class Ahoy::Visit include Mongoid::Document # associations has_many :events, class_name: "Ahoy::Event" belongs_to :user, index: true, optional: true # required field :visit_token, type: String field :visitor_token, type: String # the rest are recommended but optional # simply remove the columns you...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy.rb
Ruby
mit
4,446
master
3,782
# stdlib require "ipaddr" # dependencies require "active_support" require "active_support/core_ext" require "safely/core" # modules require_relative "ahoy/utils" require_relative "ahoy/base_store" require_relative "ahoy/controller" require_relative "ahoy/database_store" require_relative "ahoy/helper" require_relative...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/generators/ahoy/install_generator.rb
Ruby
mit
4,446
master
950
require "rails/generators" module Ahoy module Generators class InstallGenerator < Rails::Generators::Base source_root File.join(__dir__, "templates") def copy_templates activerecord = defined?(ActiveRecord) mongoid = defined?(Mongoid) selection = if activerecord &&...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/generators/ahoy/base_generator.rb
Ruby
mit
4,446
master
290
require "rails/generators" module Ahoy module Generators class BaseGenerator < Rails::Generators::Base source_root File.join(__dir__, "templates") def copy_templates template "base_store_initializer.rb", "config/initializers/ahoy.rb" end end end end
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/generators/ahoy/activerecord_generator.rb
Ruby
mit
4,446
master
1,819
require "rails/generators" require "rails/generators/active_record" module Ahoy module Generators class ActiverecordGenerator < Rails::Generators::Base include ActiveRecord::Generators::Migration source_root File.join(__dir__, "templates") class_option :database, type: :string, aliases: "-d" ...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/generators/ahoy/mongoid_generator.rb
Ruby
mit
4,446
master
515
require "rails/generators" module Ahoy module Generators class MongoidGenerator < Rails::Generators::Base source_root File.join(__dir__, "templates") def copy_templates template "database_store_initializer.rb", "config/initializers/ahoy.rb" template "mongoid_visit_model.rb", "app/mod...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy/query_methods.rb
Ruby
mit
4,446
master
3,081
module Ahoy module QueryMethods extend ActiveSupport::Concern module ClassMethods def where_event(name, properties = {}) where(name: name).where_props(properties) end def where_props(properties) return all if properties.empty? adapter_name = respond_to?(:connection...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy/helper.rb
Ruby
mit
4,446
master
1,103
module Ahoy module Helper def amp_event(name, properties = {}) url = Ahoy::Engine.routes.url_helpers.events_url( url_options.slice(:host, :port, :protocol).merge( name: name, properties: properties, screen_width: "SCREEN_WIDTH", screen_height: "SCREEN_HEIGHT",...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy/database_store.rb
Ruby
mit
4,446
master
3,055
module Ahoy class DatabaseStore < BaseStore def track_visit(data) @visit = visit_model.create!(slice_data(visit_model, data)) rescue => e raise e unless unique_exception?(e) # so next call to visit will try to fetch from DB if defined?(@visit) remove_instance_variable(:@visit)...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy/engine.rb
Ruby
mit
4,446
master
1,078
module Ahoy class Engine < ::Rails::Engine initializer "ahoy", after: "sprockets.environment" do Ahoy.logger ||= Rails.logger # allow Devise to be loaded after Ahoy require "ahoy/warden" if defined?(Warden) next unless Ahoy.quiet # Parse PATH_INFO by assets prefix AHOY_PREFI...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy/model.rb
Ruby
mit
4,446
master
366
module Ahoy module Model def visitable(name = :visit, **options) class_eval do belongs_to(name, class_name: "Ahoy::Visit", optional: true, **options) before_create :set_ahoy_visit end class_eval %{ def set_ahoy_visit self.#{name} ||= Ahoy.instance.try(:visit_or_...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy/tracker.rb
Ruby
mit
4,446
master
7,181
require "active_support/core_ext/digest/uuid" module Ahoy class Tracker UUID_NAMESPACE = "a82ae811-5011-45ab-a728-569df7499c5f" attr_reader :request, :controller def initialize(**options) @store = Ahoy::Store.new(options.merge(ahoy: self)) @controller = options[:controller] @request =...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy/controller.rb
Ruby
mit
4,446
master
1,336
module Ahoy module Controller def self.included(base) if base.respond_to?(:helper_method) base.helper_method :current_visit base.helper_method :ahoy end base.before_action :track_ahoy_visit, unless: -> { Ahoy.api_only } base.around_action :set_ahoy_request_store, unless: ->...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy/visit_properties.rb
Ruby
mit
4,446
master
3,258
require "cgi" require "device_detector" require "uri" module Ahoy class VisitProperties attr_reader :request, :params, :referrer, :landing_page def initialize(request, api:) @request = request @params = request.params @referrer = api ? params["referrer"] : request.referer @landing_pa...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy/base_store.rb
Ruby
mit
4,446
master
2,200
module Ahoy class BaseStore attr_writer :user def initialize(options) @user = options[:user] @options = options end def track_visit(data) end def track_event(data) end def geocode(data) end def authenticate(data) end def visit end def user ...
github
ankane/ahoy
https://github.com/ankane/ahoy
lib/ahoy/geocode_v2_job.rb
Ruby
mit
4,446
master
926
module Ahoy class GeocodeV2Job < ActiveJob::Base queue_as { Ahoy.job_queue } def perform(visit_token, ip) location = begin Geocoder.search(ip).first rescue NameError raise "Add the geocoder gem to your Gemfile to use geocoding" rescue => e Ahoy.log ...
github
ankane/ahoy
https://github.com/ankane/ahoy
app/controllers/ahoy/visits_controller.rb
Ruby
mit
4,446
master
314
module Ahoy class VisitsController < BaseController def create ahoy.track_visit render json: { visit_token: ahoy.visit_token, visitor_token: ahoy.visitor_token, # legacy visit_id: ahoy.visit_token, visitor_id: ahoy.visitor_token } end end end
github
ankane/ahoy
https://github.com/ankane/ahoy
app/controllers/ahoy/base_controller.rb
Ruby
mit
4,446
master
1,386
module Ahoy class BaseController < ApplicationController filters = _process_action_callbacks.map(&:filter) - Ahoy.preserve_callbacks skip_before_action(*filters, raise: false) skip_after_action(*filters, raise: false) skip_around_action(*filters, raise: false) if respond_to?(:protect_from_forgery...
github
ankane/ahoy
https://github.com/ankane/ahoy
app/controllers/ahoy/events_controller.rb
Ruby
mit
4,446
master
1,471
module Ahoy class EventsController < Ahoy::BaseController def create events = if params[:name] # legacy API and AMP [request.params] elsif params[:events] request.params[:events] else data = if params[:events_json] req...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
Gemfile
Ruby
mit
4,441
main
222
source "https://rubygems.org" gemspec gem "minitest", "~> 5.14" gem "rake", "~> 13.0" gem "rdoc", "~> 7.2" gem "rubocop", "~> 1.12" unless RUBY_PLATFORM == 'java' gem 'brotli', '>= 0.5' gem 'zstd-ruby', '~> 2.0' end
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
mechanize.gemspec
Ruby
mit
4,441
main
2,839
# coding: utf-8 # frozen_string_literal: true require_relative 'lib/mechanize/version' Gem::Specification.new do |spec| spec.name = "mechanize" spec.version = Mechanize::VERSION spec.homepage = "https://github.com/sparklemotion/mechanize" spec.summary = 'The Mechanize library is used for automating interaction...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
Rakefile
Ruby
mit
4,441
main
1,503
require 'rubygems' begin require "bundler/gem_tasks" rescue LoadError end require 'rdoc/task' require 'rake/testtask' task :prerelease => [:clobber_rdoc, :test] desc "Update SSL Certificate" task('ssl_cert') do |p| sh "openssl genrsa -des3 -out server.key 1024" sh "openssl req -new -key server.key -out server...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize.rb
Ruby
mit
4,441
main
36,294
# frozen_string_literal: true require 'mechanize/version' require 'fileutils' require 'forwardable' require 'net/http/digest_auth' require 'net/http/persistent' require 'nokogiri' require 'openssl' require 'pp' require 'stringio' require 'uri' require 'webrick/httputils' require 'zlib' ## # The Mechanize library is us...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/directory_saver.rb
Ruby
mit
4,441
main
2,075
# frozen_string_literal: true ## # Unlike Mechanize::FileSaver, the directory saver places all downloaded files # in a single pre-specified directory. # # You must register the directory to save to before using the directory saver: # # agent.pluggable_parser['image'] = \ # Mechanize::DirectorySaver.save_to 'image...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/download.rb
Ruby
mit
4,441
main
1,903
# frozen_string_literal: true ## # Download is a pluggable parser for downloading files without loading them # into memory first. You may subclass this class to handle content types you # do not wish to load into memory first. # # See Mechanize::PluggableParser for instructions on using this class. class Mechanize::D...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/test_case.rb
Ruby
mit
4,441
main
7,773
# frozen_string_literal: true require 'mechanize' require 'logger' require 'tempfile' require 'tmpdir' require 'webrick' require 'zlib' require 'rubygems' begin gem 'minitest' rescue Gem::LoadError end require 'minitest/autorun' ## # A generic test case for testing mechanize. Using a subclass of # Mechanize::Tes...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/unauthorized_error.rb
Ruby
mit
4,441
main
410
# frozen_string_literal: true class Mechanize::UnauthorizedError < Mechanize::ResponseCodeError attr_reader :challenges def initialize page, challenges, message super page, message @challenges = challenges end def to_s out = super if @challenges then realms = @challenges.map(&:realm_na...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/page.rb
Ruby
mit
4,441
main
14,871
# frozen_string_literal: true ## # This class encapsulates an HTML page. If Mechanize finds a content # type of 'text/html', this class will be instantiated and returned. # # Example: # # require 'mechanize' # # agent = Mechanize.new # agent.get('http://google.com/').class # => Mechanize::Page class Mechanize::...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/content_type_error.rb
Ruby
mit
4,441
main
405
# frozen_string_literal: true ## # This error is raised when a pluggable parser tries to parse a content type # that it does not know how to handle. For example if Mechanize::Page were to # try to parse a PDF, a ContentTypeError would be thrown. class Mechanize::ContentTypeError < Mechanize::Error attr_reader :cont...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/redirect_limit_reached_error.rb
Ruby
mit
4,441
main
399
# frozen_string_literal: true ## # Raised when too many redirects are sent class Mechanize::RedirectLimitReachedError < Mechanize::Error attr_reader :page attr_reader :redirects attr_reader :response_code def initialize page, redirects @page = page @redirects = redirects @response_co...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/file_request.rb
Ruby
mit
4,441
main
372
# frozen_string_literal: true ## # A wrapper for a file URI that makes a request that works like a # Net::HTTPRequest class Mechanize::FileRequest attr_accessor :uri def initialize uri @uri = uri end def add_field *a end alias []= add_field def path @uri.path end def each_header end ...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/util.rb
Ruby
mit
4,441
main
4,553
# frozen_string_literal: true require 'cgi' require 'nkf' class Mechanize::Util # default mime type data for Page::Image#mime_type. # You can use another Apache-compatible mimetab. # mimetab = WEBrick::HTTPUtils.load_mime_types('/etc/mime.types') # Mechanize::Util::DefaultMimeTypes.replace(mimetab) Defau...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/response_code_error.rb
Ruby
mit
4,441
main
808
# frozen_string_literal: true # This error is raised when Mechanize encounters a response code it does not # know how to handle. Currently, this exception will be thrown if Mechanize # encounters response codes other than 200, 301, or 302. Any other response # code is up to the user to handle. class Mechanize::Respo...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/file_saver.rb
Ruby
mit
4,441
main
875
# frozen_string_literal: true ## # This is a pluggable parser that automatically saves every file it # encounters. Unlike Mechanize::DirectorySaver, the file saver saves the # responses as a tree, reflecting the host and file path. # # == Example # # This example saves all .pdf files # # require 'mechanize' # # ag...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/http.rb
Ruby
mit
4,441
main
226
# frozen_string_literal: true ## # Mechanize::HTTP contains classes for communicated with HTTP servers. All # API under this namespace is considered private and is subject to change at # any time. class Mechanize::HTTP end
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/form.rb
Ruby
mit
4,441
main
18,825
# frozen_string_literal: true require 'mechanize/element_matcher' # This class encapsulates a form parsed out of an HTML page. Each type of # input field available in a form can be accessed through this object. # # == Examples # # Find a form and print out its fields # # form = page.forms.first # => Mechanize::Form...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/history.rb
Ruby
mit
4,441
main
1,284
# frozen_string_literal: true ## # This class manages history for your mechanize object. class Mechanize::History < Array attr_accessor :max_size def initialize(max_size = nil) @max_size = max_size @history_index = {} end def initialize_copy(orig) super @history_index = orig.instance_...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/cookie_jar.rb
Ruby
mit
4,441
main
4,657
# frozen_string_literal: true warn 'mechanize/cookie_jar will be deprecated. Please migrate to the http-cookie APIs.' if $VERBOSE require 'http/cookie_jar' require 'http/cookie_jar/yaml_saver' require 'mechanize/cookie' class Mechanize module CookieJarIMethods include CookieDeprecated def add(arg1, arg2 =...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/parser.rb
Ruby
mit
4,441
main
3,460
# frozen_string_literal: true ## # The parser module provides standard methods for accessing the headers and # content of a response that are shared across pluggable parsers. module Mechanize::Parser extend Forwardable special_filenames = Regexp.union %w[ AUX COM1 COM2 COM3 COM4 COM5 ...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/file_response.rb
Ruby
mit
4,441
main
1,436
# frozen_string_literal: true ## # Fake response for dealing with file:/// requests class Mechanize::FileResponse attr_reader :file_path def initialize(file_path) @file_path = file_path @uri = nil end def read_body raise Mechanize::ResponseCodeError.new(self) unless File.exist? @file...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/element_not_found_error.rb
Ruby
mit
4,441
main
434
# frozen_string_literal: true ## # Raised when an an element was not found on the Page class Mechanize::ElementNotFoundError < Mechanize::Error attr_reader :source attr_reader :element attr_reader :conditions def initialize source, element, conditions @source = source @element = element @...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/prependable.rb
Ruby
mit
4,441
main
2,396
# frozen_string_literal: true # Fake implementation of prepend(), which does not support overriding # inherited methods nor methods that are formerly overridden by # another invocation of prepend(). # # Here's what <Original>.prepend(<Wrapper>) does: # # - Create an anonymous stub module (hereinafter <Stub>) and define...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/element_matcher.rb
Ruby
mit
4,441
main
1,811
# frozen_string_literal: true module Mechanize::ElementMatcher def elements_with singular, plural = "#{singular}s" class_eval <<-CODE def #{plural}_with criteria = {} selector = method = nil if String === criteria then criteria = {:name => criteria} else criteria...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/cookie.rb
Ruby
mit
4,441
main
1,425
# frozen_string_literal: true warn 'mechanize/cookie will be deprecated. Please migrate to the http-cookie APIs.' if $VERBOSE require 'http/cookie' class Mechanize module CookieDeprecated def __deprecated__(to = nil) $VERBOSE or return method = caller_locations(1,1).first.base_label to ||= me...
github
sparklemotion/mechanize
https://github.com/sparklemotion/mechanize
lib/mechanize/headers.rb
Ruby
mit
4,441
main
424
# frozen_string_literal: true class Mechanize::Headers < Hash def [](key) super(key.downcase) end def []=(key, value) super(key.downcase, value) end def key?(key) super(key.downcase) end def canonical_each block_given? or return enum_for(__method__) each { |key, value| key = k...