Class: BatCave::DSL

Inherits:
Object
  • Object
show all
Includes:
Support::EnvPath, Support::Git
Defined in:
lib/batcave/dsl.rb

Overview

TODO(sissel): DSL is a poor name for this class. Fix it later. TODO(sissel): Split the ‘THING’ processor from the ‘Thing’ instances

Defined Under Namespace

Classes: IvarBinding

Instance Method Summary collapse

Methods included from Support::EnvPath

#path

Methods included from Support::Git

#project_root

Constructor Details

#initialize(configfile, thing, args) ⇒ DSL

Returns a new instance of DSL.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/batcave/dsl.rb', line 15

def initialize(configfile, thing, args)
  @args = args
  @thing = thing
  @configfile = configfile
  @logger = Cabin::Channel.get("batcave")

  # Default environment is project.
  @environment = :project
  # Update all files by default
  @create_only = []

  @target ||= path(@environment)
  @sourcedir = File.dirname(@configfile)
  @sync = true

  # Make this 'thing' argument into a command by
  # dynamically making a new subclass of Clamp::Command
  @command = Class.new(Clamp::Command).new("<internal dsl thing>")
  class << @command
    def execute
      # nothing to do, we just want to parse flags.
    end
  end
  binding.eval(File.read(@configfile), @configfile)
end

Instance Method Details

#environment(env = nil) ⇒ Object

Set the environment this thing is operating in.

Valid environments are: :system, :user, :project, :path

This helps hint batcave update operations so you can just update your user, project, etc, instead of everything at once.



194
195
196
197
198
199
# File 'lib/batcave/dsl.rb', line 194

def environment(env=nil)
  if !env.nil?
    @environment = env
  end
  return @environment
end

#executeObject

def to_yaml



211
212
213
# File 'lib/batcave/dsl.rb', line 211

def execute
  sync if @sync
end

#thingObject

def environment



201
202
203
# File 'lib/batcave/dsl.rb', line 201

def thing
  return @thing
end

#to_hashObject

def thing



205
206
207
208
209
# File 'lib/batcave/dsl.rb', line 205

def to_hash
  return {
    "args" => @args
  }
end