Module: Toast::ConfigDSL

Defined in:
lib/toast/config_dsl.rb

Defined Under Namespace

Classes: Base, InCollection

Class Method Summary collapse

Class Method Details

.get_comments(arg, access) ⇒ Object

fields (readables and writables) can have comments , if passed by Arrays of the form:

symbol, comment

returns a Hash of all commented or uncommented fields as: { FIELD_NAME => {:comment => COMMENT, :type => type } }



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/toast/config_dsl.rb', line 217

def self.get_comments arg, access
  comments = {}

  if arg.is_a? Array
    arg.each do |f|
      if f.is_a? Array
        comments[ f.first.to_s ] = {:comment => f[1].to_s, :access => access, :type => f[2]}
      else
        comments[ f.to_s ] = {:comment => '[ no comment ]', :access => access, :type => nil}
      end
    end
  end

  comments
end

.normalize(list, name) ⇒ Object

checks if list is made of symbols and strings converts a single value to an Array converts all symbols to strings



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/toast/config_dsl.rb', line 193

def self.normalize list, name
  # make single element list
  list = [list] unless list.is_a? Array

  # remove all comments
  list = list.map{|x| x.is_a?(Array) ? x.first : x}

  # flatten
  list = [list].flatten

  # check class and stringify
  list.map do |x|
    if (!x.is_a?(Symbol) && !x.is_a?(String))
      raise "Toast Config Error: '#{name}' should be a list of Symbols"
    else
      x.to_s
    end
  end
end