Class: Dogen::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dogen/base.rb

Instance Method Summary collapse

Instance Method Details

#configurationObject



31
32
33
# File 'lib/dogen/base.rb', line 31

def configuration
  @configuration ||= Configuration.new
end

#generate(path, opts = {}) ⇒ Object



26
27
28
29
# File 'lib/dogen/base.rb', line 26

def generate(path, opts = {})
  new_file_path = File.join(current_dir, File.basename(path))
  File.write(new_file_path, provider.get(path, data: opts).source)
end

#parse_opts(args) ⇒ Object



17
18
19
# File 'lib/dogen/base.rb', line 17

def parse_opts(args)
  Hash[(args.map { |item| item.split(':') })]
end

#read_opts_from_json(path) ⇒ Object



21
22
23
24
# File 'lib/dogen/base.rb', line 21

def read_opts_from_json(path)
  raise 'File not found' unless File.exist?(path)
  JSON.parse(IO.read(path))
end

#set_repository(args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/dogen/base.rb', line 6

def set_repository(args)
  source, place = args.first.to_s.split('::')

  if source.downcase == 'path'
    raise "Missing path: #{place}" unless File.directory?(place)
    configuration.set(repository: { source: 'path', place: place })
  else
    raise "Unknown source #{source}"
  end
end