Class: Propro::Source
- Inherits:
-
Object
- Object
- Propro::Source
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#provisioner ⇒ Object
readonly
Returns the value of attribute provisioner.
Instance Method Summary collapse
- #can_provision? ⇒ Boolean
- #exports ⇒ Object
- #file_name ⇒ Object
- #file_path ⇒ Object
-
#initialize(name) ⇒ Source
constructor
A new instance of Source.
- #is_library? ⇒ Boolean
- #load ⇒ Object
- #specified_exports ⇒ Object
- #to_bash ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/propro/source.rb', line 3 def name @name end |
#provisioner ⇒ Object (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
34 35 36 |
# File 'lib/propro/source.rb', line 34 def can_provision? @can_provision end |
#exports ⇒ Object
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_name ⇒ Object
20 21 22 |
# File 'lib/propro/source.rb', line 20 def file_name "#{@name}.sh" end |
#file_path ⇒ Object
24 25 26 |
# File 'lib/propro/source.rb', line 24 def file_path File.join(Propro::Package.root, file_name) end |
#is_library? ⇒ Boolean
38 39 40 |
# File 'lib/propro/source.rb', line 38 def is_library? @is_library end |
#load ⇒ Object
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_exports ⇒ Object
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_bash ⇒ Object
58 59 60 61 62 63 |
# File 'lib/propro/source.rb', line 58 def to_bash <<-SH # Propro package: #{file_name} #{@src} SH end |