Class: KnifeCookbookDoc::ResourceModel

Inherits:
Object
  • Object
show all
Includes:
Chef::Mixin::ConvertToClassName, BaseModel
Defined in:
lib/knife_cookbook_doc/resource_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseModel

#short_description, #top_level_description, #top_level_descriptions

Constructor Details

#initialize(cookbook_name, file) ⇒ ResourceModel

Returns a new instance of ResourceModel.



7
8
9
10
# File 'lib/knife_cookbook_doc/resource_model.rb', line 7

def initialize(cookbook_name, file)
  @native_resource = build_native_from_file(cookbook_name, file)
  load_descriptions
end

Instance Attribute Details

#native_resourceObject (readonly)

Returns the value of attribute native_resource.



5
6
7
# File 'lib/knife_cookbook_doc/resource_model.rb', line 5

def native_resource
  @native_resource
end

Instance Method Details

#action_description(action) ⇒ Object



37
38
39
# File 'lib/knife_cookbook_doc/resource_model.rb', line 37

def action_description(action)
  action_descriptions[action.to_s]
end

#action_descriptionsObject



41
42
43
# File 'lib/knife_cookbook_doc/resource_model.rb', line 41

def action_descriptions
  @action_descriptions ||= {}
end

#actionsObject

Return the unique set of actions, with the default one first, if there is a single default The :nothing action will show up only if it is the only one, or it is explicitly documented



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/knife_cookbook_doc/resource_model.rb', line 18

def actions
  return @actions unless @actions.nil?

  if default_action.is_a?(Array)
    @actions = @native_resource.actions
  else
    @actions = [default_action].compact + @native_resource.actions.sort.uniq.select { |a| a != default_action }
  end

  @actions.delete(:nothing) if @actions != [:nothing] && action_descriptions[:nothing].nil?
  @actions
end

#attribute_default_value(attribute) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/knife_cookbook_doc/resource_model.rb', line 58

def attribute_default_value(attribute)
  if attribute_has_default_value?(attribute)
    return @native_resource.attribute_specifications[attribute][:default]
  else
    return nil
  end
end

#attribute_description(attribute) ⇒ Object



49
50
51
# File 'lib/knife_cookbook_doc/resource_model.rb', line 49

def attribute_description(attribute)
  attribute_descriptions[attribute.to_s]
end

#attribute_descriptionsObject



66
67
68
# File 'lib/knife_cookbook_doc/resource_model.rb', line 66

def attribute_descriptions
  @attribute_descriptions ||= {}
end

#attribute_has_default_value?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/knife_cookbook_doc/resource_model.rb', line 53

def attribute_has_default_value?(attribute)
  specification = @native_resource.attribute_specifications[attribute]
  specification && specification.has_key?(:default)
end

#attributesObject



45
46
47
# File 'lib/knife_cookbook_doc/resource_model.rb', line 45

def attributes
  @native_resource.attribute_specifications.keys
end

#default_actionObject



31
32
33
34
35
# File 'lib/knife_cookbook_doc/resource_model.rb', line 31

def default_action
  action = @native_resource.default_action
  return action.first if action.is_a?(Array) && action.length == 1
  action
end

#nameObject



12
13
14
# File 'lib/knife_cookbook_doc/resource_model.rb', line 12

def name
  @native_resource.resource_name
end