Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 11, 2025

The nginx_site resource previously defined the config_file method inside the action_class block, making it inaccessible from resource instances. This prevented useful usage patterns like:

site = nginx_site 'service-discovery' do
  conf_dir ::File.join(config.nginx_dir, 'sites-available')
  cookbook 'dsi-consul-servers'
  template 'service-discovery.conf.erb'
  variables(
     ...
  )
  action :create
end

link site.config_file do    # This would fail before this change
  to "../sites-enabled/#{site.name}"
end

This PR moves the config_file method from inside the action_class block to the main resource body, making it accessible on resource instances while preserving all existing functionality.

Changes made:

  • Moved config_file method definition outside of action_class
  • Updated method implementation to use conf_dir and name directly instead of new_resource.conf_dir and new_resource.name
  • Added test case to verify external accessibility works correctly
  • All existing internal usage continues to work unchanged

Result:
Users can now access the configuration file path externally:

site = nginx_site 'my-site' do
  conf_dir '/etc/nginx/sites-available'
  action :create
end

puts site.config_file  # Returns: /etc/nginx/sites-available/my-site.conf

This is a minimal, backward-compatible change that enables the requested functionality without breaking any existing behavior.

Fixes #620.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor Author

Copilot AI commented Sep 11, 2025

@damacus 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@Copilot Copilot AI changed the title [WIP] Extract useful methods to outside of action_class Extract config_file method from action_class to enable external access Sep 11, 2025
Copilot finished work on behalf of damacus September 11, 2025 23:16
@Copilot Copilot AI requested a review from damacus September 11, 2025 23:16
Comment on lines +66 to +67
def config_file
::File.join(conf_dir, "#{name}.conf")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this to the helpers.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract useful methods to outside of action_class
2 participants