module Nexus3
  # Load Groovy scripts via the Nexus3 API.
  class Scripts
    def self.groovy_script_location(script_name, node)
      cookbook = node.run_context.cookbook_collection['nexus3']
      cookbook.preferred_filename_on_disk_location(node, :files, "#{script_name}.groovy")
    end

    def self.groovy_content(script_name, node)
      ::File.read groovy_script_location(script_name, node)
    end
  end
end

module Nexus3
  # Load Groovy scripts via the Nexus3 API.
  class Scripts
    def self.groovy_script_location(script_name, node, cookbook_name)
      cookbook = node.run_context.cookbook_collection[cookbook_name]
      cookbook.preferred_filename_on_disk_location(node, :files, "#{script_name}.groovy")
    end

    def self.groovy_content(script_name, node, cookbook_name = 'nexus3')
      ::File.read groovy_script_location(script_name, node, cookbook_name)
    end
  end
end

Allow other cookbooks to load their groovy scripts existing helpers
Allow other cookbooks to load their groovy scripts existing helpers

If we want to use ::Nexus3.groovy_content helper to upload a custom
groovy scripts, we should be able to specify in which cookbook the
script file resides, else we would need to merge all users scripts
in this cookbook.
