Sha256: 0a18fae3f4cac874285c879051b79c6d890e7aa19673e6c2ec197bb403eb10d2

Contents?: true

Size: 1.24 KB

Versions: 12

Compression:

Stored size: 1.24 KB

Contents

module KnifeCookbookDoc
  class DefinitionsModel
    include KnifeCookbookDoc::BaseModel
    attr_reader :name

    def initialize(name, filename)
      @name = name
      @filename = filename
      load_descriptions
    end

    def params
      @params ||= {}
    end

    private

    def load_descriptions
      description = extract_description
      current_section = 'main'
      description.each_line do |line|
        if /^ *\@param *([^ ]*) (.*)$/ =~ line
          params[$1] = {}
          params[$1]['descr'] = $2.strip
        elsif /^ *\@section (.*)$/ =~ line
          current_section = $1.strip
        else
          lines = (top_level_descriptions[current_section] || [])
          lines << line.gsub("\n", '')
          top_level_descriptions[current_section] = lines
        end
      end
      load_properties
    end

    def load_properties
      code = IO.read(@filename)
      code.gsub(/^ *define (.*?) (?=do)/m) do
        all = $1.split(' ', 2)
        @name = all.shift.gsub(/:|,/, '')
        next if all.empty?
        all = eval("{#{all.last}}") rescue {}
        all.each do |k, v|
          p_name = k.to_s
          params[p_name] ||= {}
          params[p_name]['default'] = v.nil? ? 'nil' : v
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
knife-cookbook-doc-0.31.1 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.31.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.30.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.29.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.28.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.27.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.26.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.25.2 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.24.2 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.25.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.24.1 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.24.0 lib/knife_cookbook_doc/definitions_model.rb