summaryrefslogtreecommitdiff
path: root/examples/plain_ruby/config.rb
blob: 93061c23c0ec33bbb83d934cc07cd4cc9ad10b10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env ruby
# frozen_string_literal: true

# Example: Plain Ruby script — no Rake, no bundler required.
#
# Run with:
#   ruby config.rb --dry      # dry run, no changes made
#   ruby config.rb --debug    # verbose output
#   ruby config.rb            # apply configuration
#
# Requires rcm to be installed as a gem, or adjust the path below:
#   require_relative '../../lib/dsl'
begin
  require 'rcm'
rescue LoadError
  require_relative '../../lib/dsl'
end

configure do
  # Write a simple text file with static content.
  file '/tmp/example/hello.txt' do
    manage directory
    'Hello, World!'
  end

  # Ensure a specific line is present in another file (idempotent).
  file '/tmp/example/hosts.txt' do
    line '127.0.0.1 localhost'
  end

  # Create a file from an inline ERB template.
  file '/tmp/example/greeting.txt' do
    from template
    'Generated on <%= Time.now.strftime("%Y-%m-%d") %>'
  end
end