diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-15 15:05:59 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-02-11 19:12:06 -0800 |
commit | 728717d1b5e489f82526b8390ab42846939392ee (patch) | |
tree | 770ffa29ce7464791352e2fd5864083b686f1226 /lib | |
parent | 3743da85e48f2fc57e48ed62c014c1070bb69f38 (diff) | |
download | chef-728717d1b5e489f82526b8390ab42846939392ee.tar.gz |
allow dep injecting chef_server_rest into objects
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/cookbook_version.rb | 13 | ||||
-rw-r--r-- | lib/chef/data_bag.rb | 7 | ||||
-rw-r--r-- | lib/chef/data_bag_item.rb | 7 | ||||
-rw-r--r-- | lib/chef/environment.rb | 7 | ||||
-rw-r--r-- | lib/chef/node.rb | 7 | ||||
-rw-r--r-- | lib/chef/role.rb | 7 |
6 files changed, 33 insertions, 15 deletions
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index c51d5798c5..b8f32a61bb 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -76,6 +76,8 @@ class Chef attr_reader :recipe_filenames_by_name attr_reader :attribute_filenames_by_short_filename + attr_accessor :chef_server_rest + # The first root path is the primary cookbook dir, from which metadata is loaded def root_dir root_paths[0] @@ -98,7 +100,7 @@ class Chef # # === Returns # object<Chef::CookbookVersion>:: Duh. :) - def initialize(name, *root_paths) + def initialize(name, *root_paths, chef_server_rest: nil) @name = name @root_paths = root_paths @frozen = false @@ -119,6 +121,7 @@ class Chef @status = :ready @file_vendor = nil @metadata = Chef::Cookbook::Metadata.new + @chef_server_rest = chef_server_rest end def version @@ -512,12 +515,12 @@ class Chef cookbook_manifest.force_save_url end - def self.chef_server_rest - Chef::REST.new(Chef::Config[:chef_server_url]) + def chef_server_rest + @chef_server_rest ||= self.chef_server_rest end - def chef_server_rest - self.class.chef_server_rest + def self.chef_server_rest + Chef::REST.new(Chef::Config[:chef_server_url]) end def destroy diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb index 528be3f2c4..8475774fa1 100644 --- a/lib/chef/data_bag.rb +++ b/lib/chef/data_bag.rb @@ -33,6 +33,8 @@ class Chef VALID_NAME = /^[\.\-[:alnum:]_]+$/ + attr_accessor :chef_server_rest + def self.validate_name!(name) unless name =~ VALID_NAME raise Exceptions::InvalidDataBagName, "DataBags must have a name matching #{VALID_NAME.inspect}, you gave #{name.inspect}" @@ -40,8 +42,9 @@ class Chef end # Create a new Chef::DataBag - def initialize + def initialize(chef_server_rest: nil) @name = '' + @chef_server_rest = chef_server_rest end def name(arg=nil) @@ -67,7 +70,7 @@ class Chef end def chef_server_rest - Chef::REST.new(Chef::Config[:chef_server_url]) + @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url]) end def self.chef_server_rest diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb index fc0ee74c0c..9f92e26c50 100644 --- a/lib/chef/data_bag_item.rb +++ b/lib/chef/data_bag_item.rb @@ -37,6 +37,8 @@ class Chef VALID_ID = /^[\.\-[:alnum:]_]+$/ + attr_accessor :chef_server_rest + def self.validate_id!(id_str) if id_str.nil? || ( id_str !~ VALID_ID ) raise Exceptions::InvalidDataBagItemID, "Data Bag items must have an id matching #{VALID_ID.inspect}, you gave: #{id_str.inspect}" @@ -49,13 +51,14 @@ class Chef attr_reader :raw_data # Create a new Chef::DataBagItem - def initialize + def initialize(chef_server_rest: nil) @data_bag = nil @raw_data = Mash.new + @chef_server_rest = chef_server_rest end def chef_server_rest - Chef::REST.new(Chef::Config[:chef_server_url]) + @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url]) end def self.chef_server_rest diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb index 33dfb52403..7d4b410639 100644 --- a/lib/chef/environment.rb +++ b/lib/chef/environment.rb @@ -33,18 +33,21 @@ class Chef include Chef::Mixin::ParamsValidate include Chef::Mixin::FromFile + attr_accessor :chef_server_rest + COMBINED_COOKBOOK_CONSTRAINT = /(.+)(?:[\s]+)((?:#{Chef::VersionConstraint::OPS.join('|')})(?:[\s]+).+)$/.freeze - def initialize + def initialize(chef_server_rest: nil) @name = '' @description = '' @default_attributes = Mash.new @override_attributes = Mash.new @cookbook_versions = Hash.new + @chef_server_rest = chef_server_rest end def chef_server_rest - Chef::REST.new(Chef::Config[:chef_server_url]) + @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url]) end def self.chef_server_rest diff --git a/lib/chef/node.rb b/lib/chef/node.rb index 6055f0e1e9..f9f6416f14 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -47,6 +47,8 @@ class Chef attr_accessor :recipe_list, :run_state, :override_runlist + attr_accessor :chef_server_rest + # RunContext will set itself as run_context via this setter when # initialized. This is needed so DSL::IncludeAttribute (in particular, # #include_recipe) can access the run_context to determine if an attributes @@ -62,7 +64,8 @@ class Chef include Chef::Mixin::ParamsValidate # Create a new Chef::Node object. - def initialize + def initialize(chef_server_rest: nil) + @chef_server_rest = chef_server_rest @name = nil @chef_environment = '_default' @@ -80,7 +83,7 @@ class Chef end def chef_server_rest - Chef::REST.new(Chef::Config[:chef_server_url]) + @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url]) end # Set the name of this Node, or return the current name. diff --git a/lib/chef/role.rb b/lib/chef/role.rb index 4b4669f4b5..4e4b2aaf80 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -32,17 +32,20 @@ class Chef include Chef::Mixin::FromFile include Chef::Mixin::ParamsValidate + attr_accessor :chef_server_rest + # Create a new Chef::Role object. - def initialize + def initialize(chef_server_rest: nil) @name = '' @description = '' @default_attributes = Mash.new @override_attributes = Mash.new @env_run_lists = {"_default" => Chef::RunList.new} + @chef_server_rest = chef_server_rest end def chef_server_rest - Chef::REST.new(Chef::Config[:chef_server_url]) + @chef_server_rest ||= Chef::REST.new(Chef::Config[:chef_server_url]) end def self.chef_server_rest |