Skip to content

Provide a similar way to config HCL (HashiCorp Configuration Language) in ruby.

License

Notifications You must be signed in to change notification settings

RiANOl/hydrochlorb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hydrochlorb

Provide a similar way to config HCL (HashiCorp Configuration Language) in ruby. And featuring all programming features (variables, iterators, functions, regexp, etc) in ruby.

Gem Version Build Status

Installation

Add the following lines to Gemfile:

gem 'hydrochlorb'

And execute:

$ bundle install

Or just install directly by:

$ gem install hydrochlorb

Usage

int = 1
float = 1.23
str = 'foo'
t = true
f = false

builder = Hydrochlorb.build do
  it_is_integer int
  it_is_negtive_integer int * -1
  it_is_float float
  it_is_negtive_float float * -1
  it_is_string str
  it_is_true t
  it_is_false f
  it_is_array (1..10).to_a
end

builder.build do
  it_is_array_object do
    it_is_also_array_object {
      something_inside_object "#{str} bar"
    }
  end

  it_is_object "obj" do
    it_is_object_with_multiple_keys "in", str do
      something_inside_object str.gsub(/f/, 'b')
    end
  end
end

puts builder.to_hcl

will output:

it_is_integer = 1
it_is_negtive_integer = -1
it_is_float = 1.23
it_is_negtive_float = -1.23
it_is_string = "foo"
it_is_true = true
it_is_false = false
it_is_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
it_is_array_object {
  it_is_also_array_object {
    something_inside_object = "foo bar"
  }
}
it_is_object "obj" {
  it_is_object_with_multiple_keys "in" "foo" {
    something_inside_object = "boo"
  }
}

And you also can use the following style to avoid conflicted name or change indentation:

builder = Hydrochlorb.build do
  add :to_s, 'this is not ruby to_s method.'
  add :Object, 'obj' do
    add :Array do
      add :Boolean, true
    end
  end
end

puts builder.to_hcl(indent: 4)

will output:

to_s = "this is not ruby to_s method."
Object "obj" {
    Array {
        Boolean = true
    }
}

About

Provide a similar way to config HCL (HashiCorp Configuration Language) in ruby.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages