Project

rupkl

0.0
The project is in a healthy, maintained state
Pkl parser for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.1.0
>= 2.0.0
 Project Readme

Gem Version CI Maintainability codecov

RuPkl

A Pkl parser for Ruby.

Installation

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

$ bundle add rupkl

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

$ gem install rupkl

Usage

You can use the methods below to load a Pkl code into a Ruby structure:

  • RuPkl.load
    • Load the given Pkl code into a Ruby structure
  • RuPkl.load_file
    • Load a Pkl code read from the given file path into a Ruby structure
require 'rupkl'

pkl = <<~'PKL'
  // From:
  // https://pkl-lang.org/main/current/language-tutorial/01_basic_config.html
  name = "Pkl: Configure your Systems in New Ways"
  attendants = 100
  isInteractive = true
  amountLearned = 13.37
PKL

RuPkl.load(pkl)
# =>
# {:name=>"Pkl:Configure your Systems in New Ways",
#  :attendants=>100,
#  :isInteractive=>true,
#  :amountLearned=>13.37}

File.open('sample.pkl', 'w') do |f|
  f.write(<<~'PKL')
    // From:
    // https://pkl-lang.org/main/current/language-tutorial/01_basic_config.html
    bird {
      name = "Common wood pigeon"
      diet = "Seeds"
      taxonomy {
        species = "Columba palumbus"
      }
    }

    exampleObjectWithJustIntElements {
      100
      42
    }

    exampleObjectWithMixedElements {
      "Bird Breeder Conference"
      (2000 + 23)
      exampleObjectWithJustIntElements
    }

    pigeonShelter {
      ["bird"] {
        name = "Common wood pigeon"
        diet = "Seeds"
        taxonomy {
          species = "Columba palumbus"
        }
      }
      ["address"] = "355 Bird St."
    }

    birdCount {
      [pigeonShelter] = 42
    }
  PKL
end

RuPkl.load_file('sample.pkl')
# =>
# {:bird=>{:name=>"Common wood pigeon", :diet=>"Seeds", :taxonomy=>{:species=>"Columba palumbus"}},
#  :exampleObjectWithJustIntElements=>[100, 42],
#  :exampleObjectWithMixedElements=>["Bird Breeder Conference", 2023, [100, 42]],
#  :pigeonShelter=>
#   {"bird"=>{:name=>"Common wood pigeon", :diet=>"Seeds", :taxonomy=>{:species=>"Columba palumbus"}},
#    "address"=>"355 Bird St."},
#  :birdCount=>
#   {{"bird"=>{:name=>"Common wood pigeon", :diet=>"Seeds", :taxonomy=>{:species=>"Columba palumbus"}},
#     "address"=>"355 Bird St."}=>42}}

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/taichi-ishitani/rupkl.

Notice

Pkl code snippets used for RSpec examples are originaly from:

Copyright & License

Copyright © 2024 Taichi Ishitani. RuPkl is licensed under the terms of the MIT License, see LICENSE.txt for further details.

Code of Conduct

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