Class: EASYFPM::Configuration
- Inherits:
-
Object
- Object
- EASYFPM::Configuration
- Defined in:
- lib/easyfpm/configuration.rb
Constant Summary collapse
- @@templateVarExpReg =
/(\{\{([\d\w\-]+?)\}\})/
- @@defaultLabelName =
"@@easyfpm-default@@"
Instance Attribute Summary collapse
-
#conf ⇒ Object
readonly
Returns the value of attribute conf.
Instance Method Summary collapse
-
#createconf(unixconfigstyle, specificLabel = nil) ⇒ Object
Create the easyfpm struct configuration from an UnixConfigStyle object.
-
#getLabelHashConf(label = nil) ⇒ Object
return an hash for the label configuration return nil if problem.
-
#getLabels ⇒ Object
return all labels into Array, nil if no labels.
-
#hasLabels? ⇒ Boolean
return true if any labels are defined.
-
#initialize(unixconfigstyle, specificLabel = nil) ⇒ Configuration
constructor
Initialize the class.
-
#print(specificLabel = nil) ⇒ Object
Print the configuration (debugging).
Constructor Details
#initialize(unixconfigstyle, specificLabel = nil) ⇒ Configuration
Initialize the class
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/easyfpm/configuration.rb', line 24 def initialize (unixconfigstyle, specificLabel=nil) raise ArgumentError, 'the argument "unixconfigstyle" must be an UnixConfigStyle object' unless unixconfigstyle.is_a? UnixConfigStyle raise ArgumentError, 'the argument "specificLabel" must be an String' unless (specificLabel.is_a? String or specificLabel == nil) @conf={} createconf(unixconfigstyle,specificLabel) raise EASYFPM::InvalidConfiguration, "No configuration found (error with the label #{specificLabel}?" if @conf.empty? replaceTemplateVars() raise EASYFPM::InvalidConfiguration, "Error(s) during validation" unless validate() end |
Instance Attribute Details
#conf ⇒ Object (readonly)
Returns the value of attribute conf.
21 22 23 |
# File 'lib/easyfpm/configuration.rb', line 21 def conf @conf end |
Instance Method Details
#createconf(unixconfigstyle, specificLabel = nil) ⇒ Object
Create the easyfpm struct configuration from an UnixConfigStyle object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/easyfpm/configuration.rb', line 36 def createconf(unixconfigstyle, specificLabel=nil) #No work if the conf is empty return nil if unixconfigstyle.isEmpty?() #No work if the conf doesn't contain the wanted label return nil unless ( specificLabel==nil or unixconfigstyle.sectionExists?(specificLabel) ) #We create an array with all keys presents in the conf allkeys=unixconfigstyle.getAllKeys(specificLabel) if (specificLabel == nil) if unixconfigstyle.haveSections?() #We have section, we create a separate conf for each one unixconfigstyle.getSections().each { |section| @conf[section]={} } else #No sections, only the default config @conf[@@defaultLabelName]={} end else #We create config only for this specific label @conf[specificLabel]={} end #We have our label(s) #It's now time to filter the configuration and create a valid conf #Foreach conf label @conf.each_key do |label| confsection=label confsection=unixconfigstyle.getRootSectionName() if (label==@@defaultLabelName) #Foreach key found allkeys.each do |param| #If the param has no value (???), next next unless unixconfigstyle.getValues(param,confsection,true) case param #Params for which each member of array is a string line when "pkg-description" @conf[label][param]=unixconfigstyle.getValues(param,confsection,true).join("\n").strip #Params for which each member is a string separated with a space when "pkg-content" @conf[label][param]=unixconfigstyle.getValues(param,confsection,true).join(" ").strip #Params for which we need to keep an array: when "pkg-depends","template-value","pkg-config-files","pkg-provides","pkg-conflicts","pkg-replaces","pkg-directories","pkg-recommends","pkg-suggests" @conf[label][param]=unixconfigstyle.getValues(param,confsection,true) else #For the others, the last one is the right string @conf[label][param]=unixconfigstyle.getValues(param,confsection,true).last.strip end #case end #allkeys.each #Now, we have specific rules : #If we have a mapping AND a content, we delete the content @conf[label].delete("pkg-content") if (@conf[label].has_key? "pkg-content" and @conf[label].has_key? "pkg-mapping") #If we have an easyfpm-pkg-changelog AND a pkg-changelog, the pkg-changelog stay @conf[label].delete("easyfpm-pkg-changelog") if (@conf[label].has_key? "easyfpm-pkg-changelog" and @conf[label].has_key? "pkg-changelog") end #@conf.each_key end |
#getLabelHashConf(label = nil) ⇒ Object
return an hash for the label configuration return nil if problem
269 270 271 272 273 |
# File 'lib/easyfpm/configuration.rb', line 269 def getLabelHashConf(label=nil) label=@@defaultLabelName if label == nil return nil unless @conf.has_key? label return @conf[label] end |
#getLabels ⇒ Object
return all labels into Array, nil if no labels
262 263 264 265 |
# File 'lib/easyfpm/configuration.rb', line 262 def getLabels() return nil unless hasLabels?() return @conf.keys() end |
#hasLabels? ⇒ Boolean
return true if any labels are defined
256 257 258 259 |
# File 'lib/easyfpm/configuration.rb', line 256 def hasLabels?() return false if @conf.has_key? @@defaultLabelName return true end |
#print(specificLabel = nil) ⇒ Object
Print the configuration (debugging)
217 218 219 220 221 222 223 224 225 |
# File 'lib/easyfpm/configuration.rb', line 217 def print(specificLabel=nil) if (specificLabel == nil) @conf.each_key do |label| printLabelConf(label) end else printLabelConf(specificLabel) end end |