├── CHANGELOG.md
├── lib
├── scalar
│ ├── version.rb
│ ├── ui.rb
│ ├── template.erb
│ └── config.rb
├── generators
│ └── scalar
│ │ └── install
│ │ ├── USAGE
│ │ ├── templates
│ │ └── initializer.rb
│ │ └── install_generator.rb
└── scalar_ruby.rb
├── .gitignore
├── bin
├── setup
├── console
└── check
├── Rakefile
├── test
├── test_helper.rb
├── test_scalar.rb
└── scalar
│ ├── test_ui.rb
│ └── test_config.rb
├── .rubocop.yml
├── Gemfile
├── scalar_ruby.gemspec
├── LICENSE
├── .github
└── workflows
│ └── check.yml
├── Gemfile.lock
├── CODE_OF_CONDUCT.md
└── README.md
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [Unreleased]
2 |
3 | ## [0.1.0] - 2024-10-16
4 |
5 | - Initial release
6 |
--------------------------------------------------------------------------------
/lib/scalar/version.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Scalar
4 | VERSION = '1.1.0'
5 | end
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .tool-versions
3 |
4 | /.bundle/
5 | /.yardoc
6 | /_yardoc/
7 | /coverage/
8 | /doc/
9 | /pkg/
10 | /spec/reports/
11 | /tmp/
12 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -euo pipefail
3 | IFS=$'\n\t'
4 | set -vx
5 |
6 | bundle install
7 |
8 | # Do any other automated setup that you need to do here
9 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'bundler/gem_tasks'
4 | require 'minitest/test_task'
5 |
6 | Minitest::TestTask.create
7 |
8 | task default: :test
9 |
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4 |
5 | require 'scalar_ruby'
6 | require 'minitest/autorun'
7 |
--------------------------------------------------------------------------------
/lib/generators/scalar/install/USAGE:
--------------------------------------------------------------------------------
1 | Description:
2 | Installs Scalar, modern open-source developer experience platform for your APIs
3 |
4 | Example:
5 | bin/rails generate scalar:install
6 |
7 | This will update:
8 | config/routes.rb
9 |
10 | This will create:
11 | config/initializers/scalar.rb
12 |
--------------------------------------------------------------------------------
/lib/scalar_ruby.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require_relative 'scalar/config'
4 | require_relative 'scalar/ui'
5 |
6 | module Scalar
7 | LIB_PATH = File.expand_path(File.dirname(__FILE__).to_s)
8 |
9 | module_function
10 |
11 | def setup
12 | yield Scalar::Config.instance
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | plugins:
2 | - rubocop-minitest
3 | - rubocop-performance
4 |
5 | AllCops:
6 | NewCops: enable
7 | SuggestExtensions: false
8 | TargetRubyVersion: 2.7
9 |
10 | Metrics/MethodLength:
11 | Exclude:
12 | - 'test/test_scalar.rb'
13 | - 'test/scalar/**/*'
14 |
15 | Style/Documentation:
16 | Enabled: false
17 |
--------------------------------------------------------------------------------
/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | require 'bundler/setup'
5 | require 'scalar/ruby'
6 |
7 | # You can add fixtures and/or initialization code here to make experimenting
8 | # with your gem easier. You can also use a different console, if you like.
9 |
10 | require 'irb'
11 | IRB.start(__FILE__)
12 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 |
5 | # Specify your gem's dependencies in scalar_ruby.gemspec
6 | gemspec
7 |
8 | gem 'minitest'
9 | gem 'rake'
10 |
11 | group :development do
12 | gem 'bundler-audit', require: false
13 | gem 'rubocop'
14 | gem 'rubocop-minitest'
15 | gem 'rubocop-performance'
16 | end
17 |
--------------------------------------------------------------------------------
/lib/scalar/ui.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'erb'
4 | require_relative 'config'
5 |
6 | module Scalar
7 | class UI
8 | def self.call(_env)
9 | [
10 | 200,
11 | { 'Content-Type' => 'text/html; charset=utf-8' },
12 | [template.result_with_hash(config: Scalar::Config.instance)]
13 | ]
14 | end
15 |
16 | def self.template
17 | ERB.new(File.read("#{Scalar::LIB_PATH}/scalar/template.erb"))
18 | end
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/lib/scalar/template.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | <%= config.page_title %>
5 |
6 |
7 |
8 |
9 |
10 |
11 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/lib/generators/scalar/install/templates/initializer.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | Scalar.setup do |config|
4 | # Specify the specific version of the Scalar. By default it uses the latest one
5 | #
6 | # config.library_url = "https://cdn.jsdelivr.net/npm/@scalar/api-reference"
7 |
8 | # Add custom page title displayed in the browser tab
9 | #
10 | # config.page_title = "API Reference"
11 |
12 | # Pass your API specification. It may be URL or file content in OpenAPI format
13 | #
14 | # config.specification = File.read(Rails.root.join("docs/openapi.yml"))
15 |
16 | # Additional Scalar configuration (e.g. theme) can be set here
17 | #
18 | # config.scalar_configuration = {
19 | # theme: "purple"
20 | # }
21 | end
22 |
--------------------------------------------------------------------------------
/bin/check:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -e # Exit immediately if a command exits with a non-zero status
4 | set -o pipefail # Fail if any part of a pipeline fails
5 |
6 | # Run bundle audit (checks for vulnerabilities in gem dependencies)
7 | echo "🔍 [ bin/check ] Analyzing Ruby gems for security vulnerabilities..."
8 | bundle exec bundle-audit check --update || { echo "❌ [ bin/check ] Bundle audit failed"; exit 1; }
9 |
10 | # Run tests
11 | echo "🧪 [ bin/check ] Running Minitest tests..."
12 | bundle exec rake test || { echo "❌ [ bin/check ] Tests failed"; exit 1; }
13 |
14 | # Run RuboCop (linter and style checker)
15 | echo "🤖 [ bin/check ] Running Rubocop..."
16 | bundle exec rubocop || { echo "❌ [ bin/check ] Rubocop failed"; exit 1; }
17 |
18 | echo "✅ [ bin/check ] Done."
19 |
--------------------------------------------------------------------------------
/scalar_ruby.gemspec:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require_relative 'lib/scalar/version'
4 |
5 | Gem::Specification.new do |spec|
6 | spec.name = 'scalar_ruby'
7 | spec.version = Scalar::VERSION
8 | spec.authors = ['Dmytro Shevchuk', 'Serhii Ponomarov']
9 | spec.email = ['dmytro@hey.com', 'sergii.ponomarov@gmail.com']
10 |
11 | spec.summary = 'A gem to automate using Scalar with Ruby apps'
12 | spec.homepage = 'https://github.com/dmytroshevchuk/scalar_ruby'
13 | spec.license = 'MIT'
14 |
15 | spec.metadata['homepage_uri'] = spec.homepage
16 | spec.metadata['rubygems_mfa_required'] = 'true'
17 | spec.metadata['source_code_uri'] = spec.homepage
18 |
19 | spec.files = Dir['{lib}/**/*', 'Rakefile', 'README.md']
20 | spec.require_paths = ['lib']
21 |
22 | spec.required_ruby_version = '>= 2.7'
23 | end
24 |
--------------------------------------------------------------------------------
/lib/scalar/config.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'json'
4 | require 'singleton'
5 |
6 | module Scalar
7 | class Config
8 | include Singleton
9 |
10 | DEFAULT_LIBRARY_URL = 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
11 | DEFAULT_PAGE_TITLE = 'API Reference'
12 | DEFAULT_SCALAR_CONFIGURATION = {}.freeze
13 | DEFAULT_SPECIFICATION = 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml'
14 |
15 | attr_accessor :library_url,
16 | :page_title,
17 | :scalar_configuration,
18 | :specification
19 |
20 | def initialize
21 | set_defaults!
22 | end
23 |
24 | def scalar_configuration_to_json
25 | JSON.dump(scalar_configuration)
26 | end
27 |
28 | def set_defaults!
29 | @library_url = DEFAULT_LIBRARY_URL
30 | @page_title = DEFAULT_PAGE_TITLE
31 | @scalar_configuration = DEFAULT_SCALAR_CONFIGURATION
32 | @specification = DEFAULT_SPECIFICATION
33 | end
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/lib/generators/scalar/install/install_generator.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module Scalar
4 | module Generators
5 | class InstallGenerator < ::Rails::Generators::Base
6 | source_root File.expand_path('templates', __dir__)
7 |
8 | desc 'Installs Scalar into a Rails app'
9 |
10 | def introduction
11 | say <<~INTRODUCTION
12 |
13 | 👋 Let's install Scalar into your Rails app!
14 |
15 | INTRODUCTION
16 | end
17 |
18 | def update_routes
19 | insert_into_file Rails.root.join('config/routes.rb'), after: 'Rails.application.routes.draw do' do
20 | "\n mount Scalar::UI, at: \"/docs\""
21 | end
22 | end
23 |
24 | def create_initializer
25 | template 'initializer.rb', 'config/initializers/scalar.rb'
26 | end
27 |
28 | def farewell
29 | say <<~FAREWELL
30 |
31 | We're done! Your can run "/docs" to observe a scalar API platform
32 |
33 | FAREWELL
34 | end
35 | end
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Dmytro Shevchuk
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/test/test_scalar.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 |
5 | class TestScalar < Minitest::Test
6 | def setup
7 | @config = Scalar::Config.instance
8 |
9 | @config.set_defaults!
10 | end
11 |
12 | def test_default_values
13 | assert_equal(Scalar::Config::DEFAULT_LIBRARY_URL, @config.library_url)
14 | assert_equal(Scalar::Config::DEFAULT_PAGE_TITLE, @config.page_title)
15 | assert_equal(Scalar::Config::DEFAULT_SCALAR_CONFIGURATION, @config.scalar_configuration)
16 | assert_equal(Scalar::Config::DEFAULT_SPECIFICATION, @config.specification)
17 | end
18 |
19 | def test_setup_allows_to_change_config
20 | Scalar.setup do |config|
21 | config.library_url = 'https://scalar.io/latest'
22 | config.page_title = 'Test API Reference'
23 | config.scalar_configuration = { theme: 'purple' }
24 | config.specification = 'https://scalar.io/api/reference'
25 | end
26 |
27 | assert_equal('https://scalar.io/latest', @config.library_url)
28 | assert_equal('Test API Reference', @config.page_title)
29 | assert_equal({ theme: 'purple' }, @config.scalar_configuration)
30 | assert_equal('https://scalar.io/api/reference', @config.specification)
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/.github/workflows/check.yml:
--------------------------------------------------------------------------------
1 | name: CI Workflow
2 |
3 | on:
4 | push:
5 | branches: [main]
6 | pull_request:
7 | branches: [main]
8 |
9 | jobs:
10 | Test-Ruby:
11 | strategy:
12 | matrix:
13 | os:
14 | - ubuntu-latest
15 | - macos-latest
16 | ruby:
17 | - '2.7'
18 | - '3.0'
19 | - '3.1'
20 | - '3.2'
21 | - '3.3'
22 | - '3.4'
23 |
24 | name: Ruby ${{ matrix.ruby }} running on ${{ matrix.os }}
25 | runs-on: ${{ matrix.os }}
26 |
27 | steps:
28 | - name: Check out repository code
29 | uses: actions/checkout@v4
30 |
31 | - name: Install Ruby
32 | uses: ruby/setup-ruby@v1
33 | env:
34 | BUNDLE_WITH: development
35 | with:
36 | ruby-version: ${{ matrix.ruby }}
37 | bundler: none
38 |
39 | - name: Install compatible Bundler for Ruby <= 2.7
40 | if: startsWith(matrix.ruby, '2')
41 | run: gem install bundler -v 2.4.22
42 |
43 | - name: Install compatible Bundler for Ruby >= 3.0
44 | if: startsWith(matrix.ruby, '3')
45 | run: gem install bundler
46 |
47 | - name: Install dependencies
48 | run: bundle install
49 |
50 | - name: Debug Environment
51 | run: |
52 | echo "Ruby version: $(ruby -v)"
53 | echo "Bundler version: $(bundle -v)"
54 |
55 | - name: Run CI pipeline for the gem
56 | run: bin/check
57 |
--------------------------------------------------------------------------------
/test/scalar/test_ui.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 |
5 | module Scalar
6 | class TestUI < Minitest::Test
7 | def setup
8 | Scalar::Config.instance.set_defaults!
9 |
10 | @status, @headers, @body = Scalar::UI.call({})
11 | end
12 |
13 | def test_call_responds_200_status
14 | assert_equal(200, @status)
15 | end
16 |
17 | def test_call_responds_correct_headers
18 | assert_equal({ 'Content-Type' => 'text/html; charset=utf-8' }, @headers)
19 | end
20 |
21 | def test_call_responds_with_html_template
22 | body_per_line = @body.first.split("\n")
23 |
24 | assert_equal(
25 | [
26 | '',
27 | '',
28 | ' ',
29 | ' API Reference',
30 | '',
31 | ' ',
32 | ' ',
33 | ' ',
34 | '',
35 | ' ',
36 | ' ',
42 | '',
43 | ' ',
44 | ' ',
45 | ''
46 | ],
47 | body_per_line
48 | )
49 | end
50 | end
51 | end
52 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | PATH
2 | remote: .
3 | specs:
4 | scalar_ruby (1.1.0)
5 |
6 | GEM
7 | remote: https://rubygems.org/
8 | specs:
9 | ast (2.4.3)
10 | bundler-audit (0.9.2)
11 | bundler (>= 1.2.0, < 3)
12 | thor (~> 1.0)
13 | json (2.13.0)
14 | language_server-protocol (3.17.0.5)
15 | lint_roller (1.1.0)
16 | minitest (5.25.5)
17 | parallel (1.27.0)
18 | parser (3.3.8.0)
19 | ast (~> 2.4.1)
20 | racc
21 | prism (1.4.0)
22 | racc (1.8.1)
23 | rainbow (3.1.1)
24 | rake (13.3.0)
25 | regexp_parser (2.10.0)
26 | rubocop (1.78.0)
27 | json (~> 2.3)
28 | language_server-protocol (~> 3.17.0.2)
29 | lint_roller (~> 1.1.0)
30 | parallel (~> 1.10)
31 | parser (>= 3.3.0.2)
32 | rainbow (>= 2.2.2, < 4.0)
33 | regexp_parser (>= 2.9.3, < 3.0)
34 | rubocop-ast (>= 1.45.1, < 2.0)
35 | ruby-progressbar (~> 1.7)
36 | unicode-display_width (>= 2.4.0, < 4.0)
37 | rubocop-ast (1.46.0)
38 | parser (>= 3.3.7.2)
39 | prism (~> 1.4)
40 | rubocop-minitest (0.38.1)
41 | lint_roller (~> 1.1)
42 | rubocop (>= 1.75.0, < 2.0)
43 | rubocop-ast (>= 1.38.0, < 2.0)
44 | rubocop-performance (1.25.0)
45 | lint_roller (~> 1.1)
46 | rubocop (>= 1.75.0, < 2.0)
47 | rubocop-ast (>= 1.38.0, < 2.0)
48 | ruby-progressbar (1.13.0)
49 | thor (1.4.0)
50 | unicode-display_width (3.1.4)
51 | unicode-emoji (~> 4.0, >= 4.0.4)
52 | unicode-emoji (4.0.4)
53 |
54 | PLATFORMS
55 | arm64-darwin-23
56 | ruby
57 |
58 | DEPENDENCIES
59 | bundler-audit
60 | minitest
61 | rake
62 | rubocop
63 | rubocop-minitest
64 | rubocop-performance
65 | scalar_ruby!
66 |
67 | BUNDLED WITH
68 | 2.5.21
69 |
--------------------------------------------------------------------------------
/test/scalar/test_config.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 |
5 | module Scalar
6 | class TestConfig < Minitest::Test
7 | def setup
8 | Scalar::Config.instance.set_defaults!
9 |
10 | @instance = Scalar::Config.instance
11 | end
12 |
13 | def test_that_library_url_accessor_is_available
14 | assert_equal(Scalar::Config::DEFAULT_LIBRARY_URL, @instance.library_url)
15 |
16 | @instance.library_url = 'https://scalar.io/latest'
17 |
18 | assert_equal('https://scalar.io/latest', @instance.library_url)
19 | end
20 |
21 | def test_that_page_title_accessor_is_available
22 | assert_equal(Scalar::Config::DEFAULT_PAGE_TITLE, @instance.page_title)
23 |
24 | @instance.page_title = 'API Documentation'
25 |
26 | assert_equal('API Documentation', @instance.page_title)
27 | end
28 |
29 | def test_that_scalar_configuration_accessor_is_available
30 | assert_equal(Scalar::Config::DEFAULT_SCALAR_CONFIGURATION, @instance.scalar_configuration)
31 |
32 | @instance.scalar_configuration = { theme: 'purple' }
33 |
34 | assert_equal({ theme: 'purple' }, @instance.scalar_configuration)
35 | end
36 |
37 | def test_scalar_configuration_to_json_returns_serialized_configuration
38 | @instance.scalar_configuration = { theme: 'purple' }
39 |
40 | assert_equal('{"theme":"purple"}', @instance.scalar_configuration_to_json)
41 | end
42 |
43 | def test_that_specification_accessor_is_available
44 | assert_equal(Scalar::Config::DEFAULT_SPECIFICATION, @instance.specification)
45 |
46 | @instance.specification = 'https://scalar.io/api/reference'
47 |
48 | assert_equal('https://scalar.io/api/reference', @instance.specification)
49 | end
50 | end
51 | end
52 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, caste, color, religion, or sexual
10 | identity and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the overall
26 | community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or advances of
31 | any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email address,
35 | without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official email address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | [INSERT CONTACT METHOD].
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series of
86 | actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or permanent
93 | ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within the
113 | community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.1, available at
119 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120 |
121 | Community Impact Guidelines were inspired by
122 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123 |
124 | For answers to common questions about this code of conduct, see the FAQ at
125 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126 | [https://www.contributor-covenant.org/translations][translations].
127 |
128 | [homepage]: https://www.contributor-covenant.org
129 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130 | [Mozilla CoC]: https://github.com/mozilla/diversity
131 | [FAQ]: https://www.contributor-covenant.org/faq
132 | [translations]: https://www.contributor-covenant.org/translations
133 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://badge.fury.io/rb/scalar_ruby)
2 | [](https://github.com/dmytroshevchuk/scalar_ruby/actions/workflows/check.yml)
3 |
4 | # Scalar API Reference for Ruby
5 |
6 | This gem simplifies the integration of [Scalar](https://scalar.com), a modern open-source developer experience platform for your APIs into Ruby applications.
7 |
8 | ## Requirements
9 |
10 | This gem is tested and supported on the following Ruby versions:
11 |
12 | - Ruby 3.0, 3.1, 3.2, 3.3
13 |
14 | Other Ruby versions might work but are not officially supported.
15 |
16 | ## Installation
17 |
18 | Add the gem to your application's Gemfile by executing in the terminal:
19 |
20 | ```bash
21 | bundle add scalar_ruby
22 | ```
23 |
24 | ## Getting Started
25 |
26 | Statistically, you will likely use the gem for the Ruby on Rails application, so here are instructions on how to set up the Scalar for this framework. In the future, we'll add examples for other popular Ruby frameworks.
27 |
28 | Once you have installed the gem, go to `config/routes.rb` and mount the `Scalar::UI` to your application.
29 |
30 | ```ruby
31 | # config/routes.rb
32 |
33 | Rails.application.routes.draw do
34 | mount Scalar::UI, at: '/docs'
35 | ...
36 | end
37 | ```
38 |
39 | Restart the Rails server, and hit `localhost:3000/docs`. You'll see the default view of the Scalar API reference. It uses the `@scalar/galaxy` OpenAPI reference so that you will have something to play with immediately.
40 |
41 | Then, if you want to use your OpenAPI specification, you need to re-configure the Scalar.
42 |
43 | First, create an initializer, say `config/initializers/scalar.rb`. Then, set the desired specification as `config.specification` using the `Scalar.setup` method:
44 |
45 | ```ruby
46 | # config/initializers/scalar.rb
47 |
48 | Scalar.setup do |config|
49 | config.specification = File.read(Rails.root.join('docs/openapi.yml'))
50 | end
51 | ```
52 |
53 | Also, you can pass a URL to the specification:
54 |
55 | ```ruby
56 | # config/initializers/scalar.rb
57 |
58 | Scalar.setup do |config|
59 | config.specification = "#{ActionMailer::Base.default_url_options[:host]/openapi.json}"
60 | end
61 | ```
62 |
63 | And that's it! More detailed information on other configuration options is in the section below.
64 |
65 | ## Integrations
66 |
67 | You can use in-build generator to setup gem into [Ruby in Rails](https://rubyonrails.org) framework by running:
68 |
69 | ```ruby
70 | bin/rails generate scalar:install
71 | ```
72 |
73 | ## Configuration
74 |
75 | Once mounted to your application, the library requires no further configuration. You can immediately start playing with the provided API reference example.
76 |
77 | Having default configurations set may be an excellent way to validate whether the Scalar fits your project. However, most users would love to utilize their specifications and be able to alter settings.
78 |
79 | The default configuration can be changed using the `Scalar.setup` method in `config/initializers/scalar.rb`.
80 |
81 | ```ruby
82 | # config/initializers/scalar.rb
83 |
84 | Scalar.setup do |config|
85 | config.page_title = 'My awesome API!'
86 | end
87 | ```
88 |
89 | Below, you’ll find a complete list of configuration settings:
90 |
91 | Parameter | Description | Default
92 | -------------------------------------------|---------------------------------------------------------|------------------------
93 | `config.page_title` | Defines the page title displayed in the browser tab. | API Reference
94 | `config.library_url` | Allows to set a specific version of Scalar. By default, it uses the latest version of Scalar, so users get the latest updates and bug fixes. | https://cdn.jsdelivr.net/npm/@scalar/api-reference
95 | `config.scalar_configuration` | Scalar has a rich set of configuration options if you want to change how it works and looks. A complete list of configuration options can be found [here](https://github.com/scalar/scalar/blob/main/documentation/configuration.md). | {}
96 | `config.specification` | Allows users to pass their OpenAPI specification to Scalar. It can be a URL to specification or a string object in JSON or YAML format. | https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml
97 |
98 | Example of setting configuration options:
99 |
100 | ```ruby
101 | # config/initializers/scalar.rb
102 |
103 | Scalar.setup do |config|
104 | config.scalar_configuration = { theme: 'purple' }
105 | end
106 | ```
107 |
108 | ## Development
109 |
110 | 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.
111 |
112 | Run `bundle exec rake install` to install this gem onto your local machine. 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](https://rubygems.org).
113 |
114 | ## Contributing
115 |
116 | Bug reports and pull requests are welcome on GitHub at https://github.com/dmytroshevchuk/scalar_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/dmytroshevchuk/scalar_ruby/blob/master/CODE_OF_CONDUCT.md).
117 |
118 | ## License
119 |
120 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
121 |
122 | ## Code of Conduct
123 |
124 | Everyone interacting in the Scalar::Ruby project’s codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/dmytroshevchuk/scalar_ruby/blob/master/CODE_OF_CONDUCT.md).
125 |
--------------------------------------------------------------------------------