class Bagboy::Chef::DataBags::Bag
Attributes
name[R]
Public Class Methods
new( opts = {} )
click to toggle source
# File lib/bagboy/chef/data_bags/bag.rb, line 8 def initialize( opts = {} ) @path = opts[:path] || '' @name = opts[:name] || '' @file = opts[:file] || Core::FileHelper.instance @scm = opts[:scm] || Core::SCMHelper.instance @knife = opts[:knife] || Bagboy::Chef::Knife.instance end
Public Instance Methods
create()
click to toggle source
# File lib/bagboy/chef/data_bags/bag.rb, line 26 def create pull if unique? Dir.mkdir @path sync true else false end end
item( name )
click to toggle source
# File lib/bagboy/chef/data_bags/bag.rb, line 20 def item( name ) name = name.gsub(/[^\w\-]/, '_') path = item_path( name + '.json' ) Item.new( {path: path, name: name, bag: @name} ) end
items()
click to toggle source
# File lib/bagboy/chef/data_bags/bag.rb, line 16 def items get_items @file.get_files( @path ) end
Private Instance Methods
data_bags_path()
click to toggle source
# File lib/bagboy/chef/data_bags/bag.rb, line 67 def data_bags_path File.expand_path( File.join(@path, '/..')) end
get_items( items )
click to toggle source
# File lib/bagboy/chef/data_bags/bag.rb, line 47 def get_items( items ) data_items = [] items.each do |item| path = item_path item name = item.sub('.json', '') data_items << Item.new( {path: path, name: name} ) end data_items end
item_path( item )
click to toggle source
# File lib/bagboy/chef/data_bags/bag.rb, line 57 def item_path ( item ) File.join( @path, item ) end
pull()
click to toggle source
# File lib/bagboy/chef/data_bags/bag.rb, line 43 def pull @scm.pull end
sync()
click to toggle source
# File lib/bagboy/chef/data_bags/bag.rb, line 39 def sync @knife.create_data_bag @name end
unique?()
click to toggle source
# File lib/bagboy/chef/data_bags/bag.rb, line 61 def unique? return false if @name == '' return false if @file.get_files(data_bags_path).include?(@name) true end