class KnifeCookbookDoc::AttributesModel
Constants
- ATTRIBUTE_REGEX
Public Class Methods
new(filename, config)
click to toggle source
# File lib/knife_cookbook_doc/attributes_model.rb, line 6 def initialize(filename, config) @filename = filename @attributes = {} @config = config load_descriptions end
Public Instance Methods
attributes()
click to toggle source
# File lib/knife_cookbook_doc/attributes_model.rb, line 13 def attributes @attributes.map do |name, options| [name, options[:description], options[:default], []] end end
Private Instance Methods
get_attribute_name(name)
click to toggle source
# File lib/knife_cookbook_doc/attributes_model.rb, line 64 def get_attribute_name(name) name.strip.gsub(/^(default|set|force_default|override|force_override)/, "node") end
load_descriptions()
click to toggle source
# File lib/knife_cookbook_doc/attributes_model.rb, line 21 def load_descriptions resource_data = IO.read(@filename) # find all attributes resource_data.gsub(/#{ATTRIBUTE_REGEX}/) do name = get_attribute_name($1) value = $2.strip if value.start_with?("{") value = "{ ... }" elsif value.start_with?("[") value = "[ ... ]" else value = value.gsub(/\A\"|\A'|\"\Z|'\Z/, '') end options = {} options[:default] = value @attributes[name] = options end # get/parse comments resource_data = resource_data.gsub(/^=begin\s*\n\s*\#\ ?<\s*\n(.*?)^\s*\# ?\>\n=end\s*\n#{ATTRIBUTE_REGEX}/m) do update_attribute($2, $1) end resource_data = resource_data.gsub(/^\s*\# ?\<\n(.*?)^\s*\# ?\>\n#{ATTRIBUTE_REGEX}/m) do update_attribute($2, $1.gsub(/^\s*\# ?/, '')) end resource_data = resource_data.gsub(/^\s*\# ?\<\>\s(.*?$)\n#{ATTRIBUTE_REGEX}/) do update_attribute($2, $1) end if @config[:ignore_missing_attribute_desc] @attributes.select! { |att_name, att_options| att_options.has_key? :description } end end
update_attribute(name, description)
click to toggle source
# File lib/knife_cookbook_doc/attributes_model.rb, line 58 def update_attribute(name, description) name = get_attribute_name(name) options = @attributes[name] options[:description] = description.strip end