Module: Chef::DSL::DataQuery
- Defined in:
- lib/chefspec/extensions/chef/data_query.rb
Instance Method Summary collapse
- #data_bag(bag) ⇒ Object
- #data_bag_item(bag, id, secret = nil) ⇒ Object
- #old_data_bag ⇒ Object
- #old_data_bag_item ⇒ Object
- #old_search ⇒ Object
- #search(*args, &block) ⇒ Object
Instance Method Details
#data_bag(bag) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/chefspec/extensions/chef/data_query.rb', line 27 def data_bag(bag) return old_data_bag(bag) unless Chef::Config[:solo] stub = ChefSpec::Stubs::DataBagRegistry.stub_for(bag) if stub.nil? raise ChefSpec::Error::DataBagNotStubbed.new(args: [bag]) end stub.result end |
#data_bag_item(bag, id, secret = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/chefspec/extensions/chef/data_query.rb', line 41 def data_bag_item(bag, id, secret = nil) return old_data_bag_item(bag, id, secret) unless Chef::Config[:solo] stub = ChefSpec::Stubs::DataBagItemRegistry.stub_for(bag, id) if stub.nil? raise ChefSpec::Error::DataBagItemNotStubbed.new(args: [bag, id]) end stub.result end |
#old_data_bag ⇒ Object
26 |
# File 'lib/chefspec/extensions/chef/data_query.rb', line 26 alias_method :old_data_bag, :data_bag |
#old_data_bag_item ⇒ Object
40 |
# File 'lib/chefspec/extensions/chef/data_query.rb', line 40 alias_method :old_data_bag_item, :data_bag_item |
#old_search ⇒ Object
5 |
# File 'lib/chefspec/extensions/chef/data_query.rb', line 5 alias_method :old_search, :search |
#search(*args, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/chefspec/extensions/chef/data_query.rb', line 6 def search(*args, &block) return old_search(*args, &block) unless Chef::Config[:solo] type = args[0] query = args[1] || '*:*' stub = ChefSpec::Stubs::SearchRegistry.stub_for(type, query) if stub.nil? raise ChefSpec::Error::SearchNotStubbed.new(args: [type, query]) end if block Array(stub.result).each {|r| block.call(r) } true else stub.result end end |