@faissaloux/gemfile
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Gemfile

Tests codecov npm version GitHub license

Installation

Install @faissaloux/gemfile using the package manager you want:

    npm install @faissaloux/gemfile
    yarn add @faissaloux/gemfile

Usage


@faissaloux/gemfile can parse both Gemfile and Gemfile.lock.

Gemfile

You can either parse a whole Gemfile file by passing its name to file().

# Gemfile

gem "json", ">= 2.0.0", "!=2.7.0", platforms: [:windows, :jruby]
gem "error_highlight", ">= 0.4.0", platforms: :ruby
gem "sdoc", git: "https://github.com/rails/sdoc.git", branch: "main"
gem "websocket-client-simple", github: "matthewd/websocket-client-simple", branch: "close-race", require: false
// index.js

import { Parser } from '@faissaloux/gemfile';

const parser = new Parser();

let parsed = parser.file('Gemfile').parse();

Or parse Gemfile text by passing it to text().

import { Parser } from '@faissaloux/gemfile';

const parser = new Parser();

let parsed = parser.text(`
    gem "json", ">= 2.0.0", "!=2.7.0", platforms: [:windows, :jruby]
    gem "error_highlight", ">= 0.4.0", platforms: :ruby
    gem "sdoc", git: "https://github.com/rails/sdoc.git", branch: "main"
    gem "websocket-client-simple", github: "matthewd/websocket-client-simple", branch: "close-race", require: false
`).parse();

Result

// console.log(parsed);

{
    "dependencies": [
        {
            "name": "json",
            "version": ">= 2.0.0, != 2.7.0",
            "platforms": [
                "windows",
                "jruby"
            ]
        },
        {
            "name": "error_highlight",
            "version": ">= 0.4.0",
            "platforms": [
                "ruby"
            ]
        },
        {
            "name": "sdoc",
            "git": "https://github.com/rails/sdoc.git",
            "branch": "main"
        },
        {
            "name": "websocket-client-simple",
            "require": "false",
            "github": "matthewd/websocket-client-simple",
            "branch": "close-race"
        }
    ]
}

Gemfile.lock

You can use file() to parse the Gemfile.lock file.

PATH
  remote: .
  specs:
    actioncable (7.2.0.alpha)
      actionpack (= 7.2.0.alpha)
      activesupport (= 7.2.0.alpha)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
      zeitwerk (~> 2.6)

GEM
  remote: https://rubygems.org/
  specs:
    addressable (2.8.6)
      public_suffix (>= 2.0.2, < 6.0)
    amq-protocol (2.3.2)
    ast (2.4.2)
    aws-eventstream (1.3.0)
    aws-partitions (1.876.0)
    aws-sdk-core (3.190.1)
      aws-eventstream (~> 1, >= 1.3.0)
      aws-partitions (~> 1, >= 1.651.0)
      aws-sigv4 (~> 1.8)
      jmespath (~> 1, >= 1.6.1)

PLATFORMS
  ruby
  x86_64-darwin
  x86_64-linux

DEPENDENCIES
  activerecord-jdbcmysql-adapter (>= 1.3.0)
  aws-sdk-s3
import { LockParser } from '@faissaloux/gemfile';

const lockParser = new LockParser();

let parsed = lockParser.file('Gemfile.lock').parse();

Or you can use text() to parse Gemfile.lock content.

import { LockParser } from '@faissaloux/gemfile';

const lockParser = new LockParser();

let parsed = lockParser.text(`PATH
    remote: .
    specs:
    actioncable (7.2.0.alpha)
        actionpack (= 7.2.0.alpha)
        activesupport (= 7.2.0.alpha)
        nio4r (~> 2.0)
        websocket-driver (>= 0.6.1)
        zeitwerk (~> 2.6)

GEM
    remote: https://rubygems.org/
    specs:
    addressable (2.8.6)
        public_suffix (>= 2.0.2, < 6.0)
    amq-protocol (2.3.2)
    ast (2.4.2)
    aws-eventstream (1.3.0)
    aws-partitions (1.876.0)
    aws-sdk-core (3.190.1)
        aws-eventstream (~> 1, >= 1.3.0)
        aws-partitions (~> 1, >= 1.651.0)
        aws-sigv4 (~> 1.8)
        jmespath (~> 1, >= 1.6.1)

PLATFORMS
  ruby
  x86_64-darwin
  x86_64-linux

DEPENDENCIES
  activerecord-jdbcmysql-adapter (>= 1.3.0)
  aws-sdk-s3
`).parse();

Result

// console.log(parsed);

{
    "PATH": {
        "remote": ".",
        "specs": {
            "actioncable (7.2.0.alpha)": [
                "actionpack (= 7.2.0.alpha)",
                "activesupport (= 7.2.0.alpha)",
                "nio4r (~> 2.0)",
                "websocket-driver (>= 0.6.1)",
                "zeitwerk (~> 2.6)"
            ]
        }
    },
    "GEM": {
        "remote": "https://rubygems.org/",
        "specs": {
            "addressable (2.8.6)": [
                "public_suffix (>= 2.0.2, < 6.0)"
            ],
            "amq-protocol (2.3.2)": [],
            "ast (2.4.2)": [],
            "aws-eventstream (1.3.0)": [],
            "aws-partitions (1.876.0)": [],
            "aws-sdk-core (3.190.1)": [
                "aws-eventstream (~> 1, >= 1.3.0)",
                "aws-partitions (~> 1, >= 1.651.0)",
                "aws-sigv4 (~> 1.8)",
                "jmespath (~> 1, >= 1.6.1)"
            ]
        }
    },
    "PLATFORMS": [
        "ruby",
        "x86_64-darwin",
        "x86_64-linux"
    ],
    "DEPENDENCIES": [
        "activerecord-jdbcmysql-adapter (>= 1.3.0)",
        "aws-sdk-s3"
    ]
}

Parser filter

You can choose which elements to return using only().

Parser.only("name", "platforms");
import { Parser } from '@faissaloux/gemfile';

Parser.only("name", "platforms");

const parser = new Parser();
let parsed = parser.text(`
    gem "json", ">= 2.0.0", "!=2.7.0", platforms: [:windows, :jruby]
    gem "error_highlight", ">= 0.4.0", platforms: :ruby
    gem "sdoc", git: "https://github.com/rails/sdoc.git", branch: "main"
    gem "websocket-client-simple", github: "matthewd/websocket-client-simple", branch: "close-race", require: false
`).parse();
// console.log(parsed);

{
    "dependencies": [
        {
            "name": "json",
            "platforms": [
                "windows",
                "jruby"
            ]
        },
        {
            "name": "error_highlight",
            "platforms": [
                "ruby"
            ]
        },
        {
            "name": "sdoc"
        },
        {
            "name": "websocket-client-simple"
        }
    ]
}

LockParser filter

You can choose which sections to return using only().

LockParser.only("PLATFORMS", "DEPENDENCIES");
import { LockParser } from '@faissaloux/gemfile';

LockParser.only("PLATFORMS", "DEPENDENCIES");

const lockParser = new LockParser();
let parsed = lockParser.text(`
PATH
    remote: .
    specs:
    actioncable (7.2.0.alpha)
        actionpack (= 7.2.0.alpha)
        activesupport (= 7.2.0.alpha)
        nio4r (~> 2.0)
        websocket-driver (>= 0.6.1)
        zeitwerk (~> 2.6)

PLATFORMS
    ruby
    x86_64-darwin
    x86_64-linux

DEPENDENCIES
    activerecord-jdbcmysql-adapter (>= 1.3.0)
    aws-sdk-s3

BUNDLED WITH
    2.5.4
`).parse();
// console.log(parsed);

{
    "PLATFORMS": [
        "ruby",
        "x86_64-darwin",
        "x86_64-linux"
    ],
    "DEPENDENCIES": [
        "activerecord-jdbcmysql-adapter (>= 1.3.0)",
        "aws-sdk-s3"
    ]
}

Readme

Keywords

Package Sidebar

Install

npm i @faissaloux/gemfile

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

68.5 kB

Total Files

9

Last publish

Collaborators

  • faissaloux