trailblazer-pro-rails 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +10 -0
- data/README.md +50 -0
- data/Rakefile +23 -0
- data/docs/debugger-ide-screenshot-august.png +0 -0
- data/lib/trailblazer/pro/rails/generator.rb +26 -0
- data/lib/trailblazer/pro/rails/railtie.rb +42 -0
- data/lib/trailblazer/pro/rails/version.rb +9 -0
- data/lib/trailblazer/pro/rails/wtf.rb +26 -0
- data/lib/trailblazer/pro/rails.rb +17 -0
- data/lib/trailblazer-pro-rails.rb +1 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2bb335727395a5d68805e4f858838d849e90cfb893f0706b5643402c7e085ece
|
4
|
+
data.tar.gz: 415bcfac3c4d618c773b5b8d1d54ae403598e472d36ca6a807845066031701a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f11b6219da35f9f97a6ff33f32eeb3fb5104bdb2cf1697986cc0731221e680ec979810021f52490611b27376456123d644365a0a83c52540c80ba910ed70c8fb
|
7
|
+
data.tar.gz: 856c418262916245973db47aa02f45b6c30f1df50ede906fd5a6c48fe5ff058cc0ceba746f69f750e2e9c8e4d1e2bca700d380830edb7dd1d73595e7bf674a28
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Trailblazer::Pro::Rails
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
In your Rails' `Gemfile`.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem "trailblazer-pro-rails"
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
1. Get your API key from https://pro.trailblazer.to/settings
|
14
|
+
2. Run our generator and enter your API key.
|
15
|
+
```
|
16
|
+
$ rails g trailblazer:pro:install
|
17
|
+
|
18
|
+
```
|
19
|
+
3. Run your operation via `#WTF?`.
|
20
|
+
```ruby
|
21
|
+
result = API::V1::Diagram::Operation::Update.WTF?(params: params)
|
22
|
+
```
|
23
|
+
|
24
|
+
4. Click the `[TRB PRO]` link in your terminal and start debugging.
|
25
|
+
|
26
|
+

|
27
|
+
|
28
|
+
Note: we're currently playing with various invocation styles and at some point you might not even have to use `Operation.wtf?` anymore.
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
## Testing
|
33
|
+
|
34
|
+
Currently, from the top directory, you need to run
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
$ rake test_1
|
38
|
+
```
|
39
|
+
This will test the generator on a new Rails app in isolation.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
$ rake test_2
|
43
|
+
```
|
44
|
+
|
45
|
+
Tests if `wtf?` works without any PRO configuration, but PRO is added.
|
46
|
+
|
47
|
+
|
48
|
+
### Architecture
|
49
|
+
|
50
|
+
* One `Gemfile` for all scenarios on `test/dummies`
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :test
|
13
|
+
|
14
|
+
|
15
|
+
# test_uninitialized_generator
|
16
|
+
Rake::TestTask.new(:test_1) do |t|
|
17
|
+
t.test_files = FileList["test/dummies/uninitialized/test/generator_test.rb"]
|
18
|
+
end
|
19
|
+
|
20
|
+
# test wtf? in different scenarios
|
21
|
+
Rake::TestTask.new(:test_2) do |t|
|
22
|
+
t.test_files = FileList["test/dummies/uninitialized/test/railtie_test.rb"]
|
23
|
+
end
|
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Trailblazer
|
2
|
+
|
3
|
+
module Pro
|
4
|
+
class Install < ::Rails::Generators::Base
|
5
|
+
# source_root File.expand_path("templates", __dir__)
|
6
|
+
|
7
|
+
def prompt_for_api_key
|
8
|
+
input = ask %(Your Trailblazer PRO API key:)
|
9
|
+
# TODO: blank
|
10
|
+
return if input.blank?
|
11
|
+
|
12
|
+
@api_key = input.chomp
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_session_file
|
16
|
+
return if @api_key.nil? # FIXME: use Trailblazer instead of thor's basic control flow.
|
17
|
+
|
18
|
+
create_file Rails::SESSION_PATH do
|
19
|
+
uninitialized_session = Trailblazer::Pro::Session::Uninitialized.new(api_key: @api_key, trailblazer_pro_host: "https://pro.trailblazer.to")
|
20
|
+
|
21
|
+
Trailblazer::Pro::Session.serialize(uninitialized_session)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Trailblazer
|
2
|
+
module Pro
|
3
|
+
module Rails
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
config.trailblazer = ActiveSupport::OrderedOptions.new # TODO: test me with trailblazer-rails
|
6
|
+
config.trailblazer.pro = ActiveSupport::OrderedOptions.new
|
7
|
+
config.trailblazer.pro.render_wtf = true
|
8
|
+
|
9
|
+
# load session and set Pro::Session.session
|
10
|
+
initializer "trailblazer-pro-rails.load_session_and_extend_operation" do
|
11
|
+
Trailblazer::Operation.extend(Pro::Operation::WTF) # TODO: only apply to selected OPs or make at least configurable?
|
12
|
+
|
13
|
+
config_options = {
|
14
|
+
render_wtf: config.trailblazer.pro.render_wtf,
|
15
|
+
}
|
16
|
+
|
17
|
+
if File.exist?(Rails::SESSION_PATH)
|
18
|
+
# TODO: warn if file not present etc.
|
19
|
+
json = File.read(Rails::SESSION_PATH)
|
20
|
+
|
21
|
+
Pro.initialize!(**Session.deserialize(json), **config_options)
|
22
|
+
|
23
|
+
trace_operations = config.trailblazer.pro.trace_operations
|
24
|
+
|
25
|
+
if trace_operations
|
26
|
+
# constants can be passed as strings to avoid autoloading issues.
|
27
|
+
trace_operations = trace_operations.collect { |klass, config| [klass.constantize, config] }.to_h
|
28
|
+
|
29
|
+
Pro.trace_operations!(trace_operations)
|
30
|
+
end
|
31
|
+
|
32
|
+
# TODO: add {Activity.invoke} here, too!
|
33
|
+
# Trailblazer::Activity.extend(Pro::Call::Activity) # FIXME: only if allowed! # TODO: only apply to selected OPs.
|
34
|
+
else # no configuration happend, yet.
|
35
|
+
Pro.initialize!(api_key: "")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Trailblazer
|
2
|
+
module Pro
|
3
|
+
module Rails
|
4
|
+
# Save the session in tmp/ if it changed after invocation.
|
5
|
+
module Wtf
|
6
|
+
extend Pro::Trace::Wtf
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def call(*args, present_options: {}, **options)
|
10
|
+
returned = super(*args, present_options: present_options, **options)
|
11
|
+
|
12
|
+
(session, trace_id, debugger_url, _trace_envelope, session_updated) = returned[-1]
|
13
|
+
|
14
|
+
if session_updated
|
15
|
+
File.write(Rails::SESSION_PATH, Session.serialize(session)) # DISCUSS: redundant
|
16
|
+
end
|
17
|
+
|
18
|
+
returned
|
19
|
+
end
|
20
|
+
|
21
|
+
# alias invoke call
|
22
|
+
singleton_class.alias_method :invoke, :call
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "rails/version"
|
4
|
+
|
5
|
+
module Trailblazer
|
6
|
+
module Pro
|
7
|
+
module Rails
|
8
|
+
SESSION_PATH = "tmp/trb-pro/session"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require "rails/generators"
|
14
|
+
require "trailblazer/pro"
|
15
|
+
require "trailblazer/pro/rails/railtie"
|
16
|
+
require "trailblazer/pro/rails/generator"
|
17
|
+
require "trailblazer/pro/rails/wtf"
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "trailblazer/pro/rails"
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trailblazer-pro-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Sutterer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: trailblazer-pro
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.1
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- apotonick@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- Gemfile
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- docs/debugger-ide-screenshot-august.png
|
39
|
+
- lib/trailblazer-pro-rails.rb
|
40
|
+
- lib/trailblazer/pro/rails.rb
|
41
|
+
- lib/trailblazer/pro/rails/generator.rb
|
42
|
+
- lib/trailblazer/pro/rails/railtie.rb
|
43
|
+
- lib/trailblazer/pro/rails/version.rb
|
44
|
+
- lib/trailblazer/pro/rails/wtf.rb
|
45
|
+
homepage: https://trailblazer.to/2.1/pro
|
46
|
+
licenses:
|
47
|
+
- LGPL-3.0
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 2.5.0
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.2.3
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Rails support for Trailblazer PRO.
|
68
|
+
test_files: []
|