Class: SOCMaker::LibInc

Inherits:
Object
  • Object
show all
Includes:
ERR, YAML_EXT
Defined in:
lib/soc_maker/lib_inc.rb

Overview

A small class, which represents a library-include information. The included directories are stored in @dirs

Instance Attribute Summary collapse

Attributes included from YAML_EXT

#src_dir

Instance Method Summary collapse

Methods included from YAML_EXT

#save_yaml

Methods included from ERR

#consistence_error, #consistence_error_if, #init_error, #init_error_if, #processing_error, #processing_error_if

Constructor Details

#initialize(opts = {}) ⇒ LibInc

This constructor does nothing special. The directories can be passed via optional arguments



54
55
56
# File 'lib/soc_maker/lib_inc.rb', line 54

def initialize( opts = {} )
  init_with( opts )
end

Instance Attribute Details

#dirsObject

the included directories



48
49
50
# File 'lib/soc_maker/lib_inc.rb', line 48

def dirs
  @dirs
end

Instance Method Details

#==(o) ⇒ Object

Equality operator



100
101
102
# File 'lib/soc_maker/lib_inc.rb', line 100

def ==(o)
  o.class == self.class && o.dirs == self.dirs
end

#encode_with(coder) ⇒ Object

Encoder method (to yaml)

coder

An instance of the Psych::Coder to encode this class to a YAML file



63
64
65
66
67
68
# File 'lib/soc_maker/lib_inc.rb', line 63

def encode_with( coder )
  init_error_if !coder.is_a?( Psych::Coder ), 
              'coder is not given as Psych::Coder'
  %w[ dirs ].
    each { |v| coder[ v ] = instance_variable_get "@#{v}" }
end

#init_with(coder) ⇒ Object

Initialization method (from yaml)

coder

An instance of the Psych::Coder to init this class from a YAML file



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/soc_maker/lib_inc.rb', line 76

def init_with( coder )
  init_error_if !( coder.is_a?( Hash ) || coder.is_a?( Psych::Coder ) ), 
              'coder is not given as Hash neither as Psych::Coder'

  init_error 'no dirs are given' if coder[ 'dirs' ] == nil
  @dirs = coder[ 'dirs' ] 

  init_error 'dirs must be of type array' if  !@dirs.is_a?( Array )
  init_error 'there must be at least one dir-entry' if @dirs.size == 0


  @dirs.each do |f|
    init_error  "The dir must be defined as string",
      field: 'dirs' if !f.is_a?( String )

    init_error "The path string has zero length",
      field: 'dirs' if f.size == 0
  end
end