Class: ChefCLI::Policyfile::Lister
- Inherits:
 - 
      Object
      
        
- Object
 - ChefCLI::Policyfile::Lister
 
 
- Defined in:
 - lib/chef-cli/policyfile/lister.rb
 
Instance Attribute Summary collapse
- 
  
    
      #config  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute config.
 - 
  
    
      #policy_lock_content  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute policy_lock_content.
 
Instance Method Summary collapse
- #active_revisions ⇒ Object
 - #empty? ⇒ Boolean
 - #http_client ⇒ Object
 - 
  
    
      #initialize(config: nil)  ⇒ Lister 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Lister.
 - #orphaned_revisions(policy_name) ⇒ Object
 - 
  
    
      #policies_by_group  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
A Hash with the following format: “dev” => { “appserver” => “1111111111111111111111111111111111111111111111111111111111111111”, “load-balancer” => “5555555555555555555555555555555555555555555555555555555555555555”, “db” => “9999999999999999999999999999999999999999999999999999999999999999” }.
 - 
  
    
      #policies_by_name  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
A Hash with the following format { “appserver” => { “1111111111111111111111111111111111111111111111111111111111111111” => {}, “2222222222222222222222222222222222222222222222222222222222222222” => {} },.
 - #revision_ids_by_group_for(policy_name) ⇒ Object
 - #revision_ids_by_group_for_each_policy ⇒ Object
 - #revision_info_for(policy_name, _revision_id_list) ⇒ Object
 - 
  
    
      #set!(policies_by_name, policies_by_group)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    
Sets internal copy of policyfile data to policies_by_name and policies_by_group.
 
Constructor Details
#initialize(config: nil) ⇒ Lister
Returns a new instance of Lister.
      115 116 117 118 119 120 121  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 115 def initialize(config: nil) @config = config @policies_by_name = nil @policies_by_group = nil @policy_lock_content = {} @active_revisions = nil end  | 
  
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
      113 114 115  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 113 def config @config end  | 
  
#policy_lock_content ⇒ Object
Returns the value of attribute policy_lock_content.
      111 112 113  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 111 def policy_lock_content @policy_lock_content end  | 
  
Instance Method Details
#active_revisions ⇒ Object
      172 173 174 175 176 177 178 179  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 172 def active_revisions @active_revisions ||= policies_by_group.inject(Set.new) do |set, (_group, policy_name_rev_id_map)| policy_name_rev_id_map.each do |policy_name, rev_id| set << rev_id end set end end  | 
  
#empty? ⇒ Boolean
      181 182 183  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 181 def empty? policies_by_name.empty? && policies_by_group.empty? end  | 
  
#http_client ⇒ Object
      185 186 187 188 189  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 185 def http_client @http_client ||= Chef::ServerAPI.new(config.chef_server_url, signing_key_filename: config.client_key, client_name: config.node_name) end  | 
  
#orphaned_revisions(policy_name) ⇒ Object
      164 165 166 167 168 169 170  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 164 def orphaned_revisions(policy_name) orphans = [] policies_by_name[policy_name].each do |rev_id, _data| orphans << rev_id unless active_revisions.include?(rev_id) end orphans end  | 
  
#policies_by_group ⇒ Object
A Hash with the following format:
"dev" => {
  "appserver" => "1111111111111111111111111111111111111111111111111111111111111111",
  "load-balancer" => "5555555555555555555555555555555555555555555555555555555555555555",
  "db" => "9999999999999999999999999999999999999999999999999999999999999999"
}
  
      140 141 142 143  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 140 def policies_by_group @policies_by_group || fetch_policy_lists @policies_by_group end  | 
  
#policies_by_name ⇒ Object
A Hash with the following format
{
  "appserver" => {
    "1111111111111111111111111111111111111111111111111111111111111111" => {},
    "2222222222222222222222222222222222222222222222222222222222222222" => {}
  },
  
      129 130 131 132  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 129 def policies_by_name @policies_by_name || fetch_policy_lists @policies_by_name end  | 
  
#revision_ids_by_group_for(policy_name) ⇒ Object
      156 157 158 159 160 161 162  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 156 def revision_ids_by_group_for(policy_name) map = policies_by_group.inject({}) do |rev_id_map, (group_name, rev_id_map_for_group)| rev_id_map[group_name] = rev_id_map_for_group[policy_name] rev_id_map end PolicyGroupRevIDMap.new(policy_name, map) end  | 
  
#revision_ids_by_group_for_each_policy ⇒ Object
      149 150 151 152 153 154  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 149 def revision_ids_by_group_for_each_policy policies_by_name.each do |policy_name, _policies| rev_id_by_group = revision_ids_by_group_for(policy_name) yield policy_name, rev_id_by_group end end  | 
  
#revision_info_for(policy_name, _revision_id_list) ⇒ Object
      145 146 147  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 145 def revision_info_for(policy_name, _revision_id_list) RevIDLockDataMap.new(policy_name, policy_lock_content[policy_name]) end  | 
  
#set!(policies_by_name, policies_by_group) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets internal copy of policyfile data to policies_by_name and policies_by_group. Used for internal testing.
      194 195 196 197 198  | 
    
      # File 'lib/chef-cli/policyfile/lister.rb', line 194 def set!(policies_by_name, policies_by_group) @policies_by_name = policies_by_name @policies_by_group = policies_by_group @active_revisions = nil end  |