Class: Arli::Lock::Formats::Template::CMakeRenderer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/arli/lock/formats/template/cmake_renderer.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arlifile) ⇒ CMakeRenderer

Returns a new instance of CMakeRenderer.



22
23
24
25
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 22

def initialize(arlifile)
  self.arlifile = arlifile
  self.erb      = ERB.new(self.class.template)
end

Class Attribute Details

.templateObject

Returns the value of attribute template.



15
16
17
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 15

def template
  @template
end

Instance Attribute Details

#arlifileObject

Returns the value of attribute arlifile.



20
21
22
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 20

def arlifile
  @arlifile
end

#erbObject

Returns the value of attribute erb.



20
21
22
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 20

def erb
  @erb
end

Instance Method Details

#arduino_librariesObject



49
50
51
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 49

def arduino_libraries
  device && device.libraries ? device.libraries.arduino || [] : []
end

#arli_library_pathObject



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 69

def arli_library_path
  if library_path.start_with?('/')
    "#{library_path}"
  elsif library_path.start_with?('~')
    "$ENV{HOME}#{library_path[1..-1]}"
  elsif library_path.start_with?('./')
    "${CMAKE_CURRENT_SOURCE_DIR}/#{library_path[2..-1]}"
  elsif library_path && library_path.size > 0
    library_path
  else
    '${CMAKE_CURRENT_SOURCE_DIR}/libraries'
  end
end

#boardObject



37
38
39
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 37

def board
  device && device.board ? device.board : 'uno'
end

#cpuObject



41
42
43
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 41

def cpu
  device && device.cpu ? device.cpu : 'atmega328p'
end

#custom_libraries_headers_onlyObject



57
58
59
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 57

def custom_libraries_headers_only
  libraries.select { |l| l.headers_only } || []
end

#deviceObject



33
34
35
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 33

def device
  arlifile_hash.device
end

#device_librariesObject



53
54
55
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 53

def device_libraries
  Array(hardware_libraries + arduino_libraries).flatten
end

#device_libraries_headers_onlyObject



61
62
63
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 61

def device_libraries_headers_only
  device_libraries.select { |l| l.headers_only } || []
end

#hardware_librariesObject



45
46
47
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 45

def hardware_libraries
  device && device.libraries ? device.libraries.hardware || [] : []
end

#library_pathObject



65
66
67
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 65

def library_path
  config.libraries.path
end

#renderObject Also known as: output



27
28
29
# File 'lib/arli/lock/formats/template/cmake_renderer.rb', line 27

def render
  erb.result(binding)
end