• Stars
    star
    16
  • Rank 1,267,951 (Top 26 %)
  • Language
    Ruby
  • Created 9 months ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Collaborative Ruby type sampling

TypeFusion

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add type_fusion

If bundler is not being used to manage dependencies, install the gem by executing:

gem install type_fusion

Running TypeFusion in the test environment

Setup TypeFusion if you only want to run TypeFusion as part of your test suite.

Minitest

You can require type_fusion/minitest in your test_helper.rb:

# test/test_helper.rb

ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"

+require "type_fusion/minitest"

class ActiveSupport::TestCase
  # ...
end

RSpec

You can require type_fusion/rspec in your spec_helper.rb:

# spec/spec_helper.rb

+require "type_fusion/rspec"

RSpec.configure do |config|
  # ...
end

Running TypeFusion in development or production

Rack

require "type_fusion/rack/middleware"

use TypeFusion::Middleware

Rails

Adding the gem to your applications Gemfile will automatically setup type_fusion.

Configuration

Setup TypeFusion in an initializer

# config/initializers/type_fusion.rb

require "type_fusion"

TypeFusion.config do |config|

  # === application_name
  #
  # Set application_name to a string which is used to know where the samples
  # came from. Set application_name to an empty string if you wish to not
  # send the application name alongside the samples.
  #
  # Default: "TypeFusion"
  # Default when using Rails: Rails.application.class.module_parent_name
  #
  # config.application_name = "YourApplication"


  # === endpoint
  #
  # Set endpoint to an URL where TypeFusion should send the samples to.
  #
  # Default: "https://gem.sh/api/v1/types/samples"
  #
  # config.endpoint = "https://your-domain.com/api/v1/types/samples"


  # === type_sample_request
  #
  # Set type_sample_request to a lambda which resolves to true/false
  # to set if type sampling should be enabled for the whole rack request.
  #
  # Default: ->(rack_env) { [true, false, false, false].sample }
  #
  # config.type_sample_request = ->(rack_env) { [true, false, false, false].sample }


  # === type_sample_tracepoint_path
  #
  # Set type_sample_tracepoint_path to a lambda which resolves
  # to true/false to check if a tracepoint_path should be sampled
  # or not.
  #
  # This can be useful when you want to only sample method calls for
  # certain gems or want to exclude a gem from being sampled.
  #
  # Example:
  # config.type_sample_tracepoint_path = ->(tracepoint_path) {
  #   return false if tracepoint_path.include?("activerecord")
  #   return false if tracepoint_path.include?("sprockets")
  #   return false if tracepoint_path.include?("some-private-gem")
  #
  #   true
  # }
  #
  # Default: ->(tracepoint_path) { true }
  #
  # config.type_sample_tracepoint_path = ->(tracepoint_path) { true }


  # === type_sample_call_rate
  #
  # Set type_sample_call_rate to 1.0 to capture 100% of method calls
  # within a rack request.
  #
  # Default: 0.001
  #
  # config.type_sample_call_rate = 0.001
end

Usage

Type sample inside a block

TypeFusion.with_sampling do
  # run code you want to type sample here
end

Type sample globally

TypeFusion.start

# run code you want to type sample here

TypeFusion.stop

Retrieve the samples

TypeFusion::Sampler.instance.samples
# => [...]
TypeFusion::Sampler.instance.samples.first

# => #<struct TypeFusion::SampleCall
#      gem_name="nokogiri"
#      gem_version="1.15.4-x86_64-darwin",
#      receiver="Nokogiri",
#      method_name=:parse,
#      application_name="TypeFusion",
#      location="/Users/marcoroth/.anyenv/envs/rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/nokogiri-1.15.4-x86_64-darwin/lib/nokogiri.rb:43",
#      type_fusion_version="0.0.4",
#      parameters=[
#        [:string, :req, String],
#        [:url, :opt, NilClass],
#        [:encoding, :opt, NilClass],
#        [:options, :opt, NilClass]
#      ],
#      return_value="Nokogiri::XML::Document"
#     >

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/type_fusion. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

Code of Conduct

Everyone interacting in the TypeFusion project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

More Repositories

1

turbo_power

Power-pack for Turbo Streams
TypeScript
323
star
2

turbo_power-rails

Power-pack for Turbo Streams
Ruby
219
star
3

current.js

A tiny 🤏 library (only 410 B) that allows you to access current `<meta>` elements
TypeScript
159
star
4

stimulus-lsp

Intelligent Stimulus tooling for Visual Studio Code and Neovim
TypeScript
127
star
5

gem.sh

Beautiful documentation for any Ruby gem.
Ruby
95
star
6

hotwire.io

Community-driven documentation and resource Hub for Hotwire.
HTML
94
star
7

turbo-morph

Morph action for Turbo Streams
JavaScript
90
star
8

boxdrop

Dropbox Clone built with StimulusReflex
Ruby
76
star
9

formulus

Client-side HTML form validations based on the browser HTML Form Validation API
TypeScript
72
star
10

phlexing

Simple ERB to Phlex converter
Ruby
71
star
11

turbo-ruby

Turbo helpers without the requirement for Rails
Ruby
41
star
12

cable-streams

Extend Turbo Streams with Custom Turbo Stream Actions and CableReady operations
TypeScript
26
star
13

stimulus-parser

Statically analyze Stimulus controllers in your project.
TypeScript
25
star
14

rails7-stimulus-reflex-esbuild

Example StimulusReflex installation using Rails 7 and esbuild
Ruby
24
star
15

stimulus-render

[PoC] HTML rendering mechanism for Stimulus Controllers
TypeScript
18
star
16

local-time

Modern fork of Basecamp's `local-time`
TypeScript
12
star
17

easy_enum

Turn any Ruby class in an easy to use enum.
Ruby
12
star
18

cable_ready.cr

[WIP] CableReady Crystal port
Crystal
10
star
19

dependabot-bump-together-action

GitHub Action to bump multiple dependencies with dependabot in a single pull request
Ruby
8
star
20

rubocop-stimulus_reflex

Code style checking for StimulusReflex
Ruby
8
star
21

netatmo-ruby

Ruby gem to interact with the Netatmo REST API
Ruby
7
star
22

railsbytes-cli

CLI to apply Railsbytes.com templates to your Rails application
Ruby
7
star
23

cable-streams-rails

Rails companion gem for the `cable-streams` NPM package
Ruby
6
star
24

ShortLook-WhatsApp

Show WhatsApp users' profile pictures in ShortLook when you receive a WhatsApp notification
Objective-C
5
star
25

rubocop-cable_ready

Code style checking for CableReady
Ruby
4
star
26

ShortLook-Bandsintown

Show Bandsintown artists' profile pictures in ShortLook when you receive a Bandsintown notification
Objective-C
4
star
27

shortlook-cli

ShortLook CLI for scaffoling a ShortLook Provider
Ruby
3
star
28

stimulus-blurhash

Stimulus Controller for BlurHash
JavaScript
2
star
29

ShortLook-RocketChat

Show RocketChat users' profile pictures in ShortLook when you receive a RocketChat notification
Objective-C
2
star
30

ShortLook-VK

Show VK users' profile pictures in ShortLook when you receive a VK notification
Objective-C
2
star
31

ShortLook-GitHub

Show GitHub users' profile pictures in ShortLook when you receive a GitHub notification
Objective-C
2
star
32

ShortLook-Line

Show Line users' profile pictures in ShortLook when you receive a Line notification
Objective-C
2
star
33

ShortLook-KakaoTalk

Show KakaoTalk Contact Photos in ShortLook when you receive a KakaoTalk notification
Objective-C
2
star
34

usersnap-stimulus-repro

HTML
1
star
35

rcrdshp-market-extension

Small extension for the RCRDSHP Marketplace
JavaScript
1
star
36

POC2u

Ruby
1
star
37

cable_ready-dsl

[PoC] An opinionated DSL for CableReady.
Ruby
1
star
38

spritpreisrechner-ruby

Ruby Wrapper for the e-control.at Spritpreisrechner HTTP API
Ruby
1
star
39

tankerkoenig-ruby

Ruby Wrapper for the Tankerkoenig API
Ruby
1
star
40

async-websocket-with-inactive-tab

HTML
1
star
41

ShortLook-Mixcloud

Show Mixcloud covers in ShortLook when you receive a Mixcloud notification
Objective-C
1
star
42

stimulus_reflex-form-serialize-app

Ruby
1
star
43

mirrOS_spotify

Modul zum Anzeigen des zurzeit spielenden Track auf Spotify.
PHP
1
star
44

openmensa-parsers

OpenMensa.org parsers
Ruby
1
star
45

ShortLook-LinkedIn

Show LinkedIn users' profile pictures in ShortLook when you receive a LinkedIn notification
Objective-C
1
star
46

ShortLook-Slack

Show Slack users' profile pictures in ShortLook when you receive a Slack notification
Objective-C
1
star
47

ShortLook-SteamChat

Show SteamChat Profile Pictures in ShortLook when you receive a SteamChat notification!
Objective-C
1
star
48

ShortLook-Xing

Show Xing users' profile pictures in ShortLook when you receive a Xing notification
Objective-C
1
star
49

ShortLook-Viber

Show Viber users' profile pictures in ShortLook when you receive a Viber notification
Objective-C
1
star
50

mirrOS_todoist

Dieses mirrOS Modul zeigt deine Aufgaben aus einer Todoist-Liste an.
PHP
1
star