Sha256: 39e99caa1fdf22048c490d58c3028c4cda19e65524750d0719293fae2978f9a3

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 ? v : 'nil'
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
knife-cookbook-doc-0.22.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.21.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.20.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.19.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.18.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.17.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.16.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.15.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.14.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.13.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.12.0 lib/knife_cookbook_doc/definitions_model.rb
knife-cookbook-doc-0.11.0 lib/knife_cookbook_doc/definitions_model.rb