Class: Propro::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/propro/source.rb

Constant Summary collapse

EXPORT_BEGIN =
'export '
COMMENT_BEGIN =
'#'
IS_LIBRARY_BEGIN =
'lib/'
FUNC_PROVISION_BEGIN =
'function provision-'
FUNC_PROVISION_NAME_RANGE =
/\Afunction provision\-([a-z\-]+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Source

Returns a new instance of Source.



11
12
13
14
15
16
17
18
# File 'lib/propro/source.rb', line 11

def initialize(name)
  @name          = name.to_s
  @exports       = []
  @can_provision = false
  @is_library    = name.start_with?(IS_LIBRARY_BEGIN)
  @src           = ''
  load
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/propro/source.rb', line 3

def name
  @name
end

#provisionerObject (readonly)

Returns the value of attribute provisioner.



3
4
5
# File 'lib/propro/source.rb', line 3

def provisioner
  @provisioner
end

Instance Method Details

#can_provision?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/propro/source.rb', line 34

def can_provision?
  @can_provision
end

#exportsObject



48
49
50
51
52
53
54
55
56
# File 'lib/propro/source.rb', line 48

def exports
  @exports.sort { |a, b|
    case
      when b.is_required? then 1
      when b.is_specified? then 0
      else -1
    end
  }
end

#file_nameObject



20
21
22
# File 'lib/propro/source.rb', line 20

def file_name
  "#{@name}.sh"
end

#file_pathObject



24
25
26
# File 'lib/propro/source.rb', line 24

def file_path
  File.join(Propro::Package.root, file_name)
end

#is_library?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/propro/source.rb', line 38

def is_library?
  @is_library
end

#loadObject



28
29
30
31
32
# File 'lib/propro/source.rb', line 28

def load
  File.open(file_path) do |file|
    file.each_line { |line| load_line(line) }
  end
end

#specified_exportsObject



42
43
44
45
46
# File 'lib/propro/source.rb', line 42

def specified_exports
  @specified_exports ||= begin
    exports.select { |e| e.is_required? || e.is_specified? }
  end
end

#to_bashObject



58
59
60
61
62
63
# File 'lib/propro/source.rb', line 58

def to_bash
  <<-SH
# Propro package: #{file_name}
#{@src}
  SH
end