This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shanty configuration and plugin documentation
- create mixin to add configuration to implementing classes - create class for merging configuration from multiple sources - add info method to plugin which returns name, description, tags, subscribed tasks and options - add option to print out plugin information on the command line
- Loading branch information
janstenpickle
committed
Oct 5, 2015
1 parent
aa266ac
commit be273ab
Showing
23 changed files
with
273 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Shanty | ||
# Public: Config class for combining configurations from multiple sources | ||
class Config | ||
attr_reader :project_config, :env_config, :plugin_config | ||
|
||
def initialize(project_config, env_config, plugin_config) | ||
@project_config = project_config || {} | ||
@env_config = env_config || {} | ||
@plugin_config = plugin_config || {} | ||
end | ||
|
||
def [](key) | ||
project_config[key] || env_config[key] || plugin_config[key] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'active_support/core_ext/hash/indifferent_access' | ||
|
||
module Shanty | ||
# Public: Config mixin for use with any class which is configurable | ||
module ConfigMixin | ||
def config | ||
@configuration ||= HashWithIndifferentAccess.new { |h, k| h[k] = HashWithIndifferentAccess.new } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<% require 'terminal-table' %> | ||
<%= $terminal.color 'PLUGIN NAME', :bold %>: | ||
|
||
<%= name %> | ||
<% unless description.nil? %><%= $terminal.color 'DESCRIPTION', :bold %>: | ||
|
||
<%= description %> | ||
<% end %><% unless subscribes.empty? %><%= $terminal.color 'TASK SUBSCRIPTIONS', :bold %>: | ||
|
||
<%= subscribes.join(', ') %> | ||
<% end %><%= $terminal.color 'TAGS', :bold %>: | ||
|
||
<%= tags.join(', ') %> | ||
<% unless config.empty? %><%= $terminal.color 'CONFIGURATION', :bold %>: | ||
|
||
<%= Terminal::Table.new(:headings => ['Config Key', 'Default Value'], rows: config) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'active_support/core_ext/hash/indifferent_access' | ||
|
||
RSpec.describe(Shanty::ConfigMixin) do | ||
subject { test_config_class.new } | ||
let(:test_config_class) { Class.new.tap { |klass| klass.include(described_class) } } | ||
|
||
describe('#config') do | ||
it('returns a hash with indifferent access') do | ||
expect(subject.config).to be_a(HashWithIndifferentAccess) | ||
end | ||
|
||
it('creates a new hash when key does not exist') do | ||
expect(subject.config[:nic]).to be_a(HashWithIndifferentAccess) | ||
expect(subject.config[:nic]).to be_empty | ||
end | ||
|
||
it('allows setting of plugin config') do | ||
subject.config[:nic][:kim] = 'cage' | ||
|
||
expect(subject.config[:nic]).to eql('kim' => 'cage') | ||
expect(subject.config[:nic][:kim]).to eql('cage') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'active_support/core_ext/hash/indifferent_access' | ||
require 'shanty/config' | ||
|
||
RSpec.describe(Shanty::Config) do | ||
subject { described_class.new(project_config, env_config, plugin_config) } | ||
|
||
describe('#[]') do | ||
let(:project_config) { HashWithIndifferentAccess.new } | ||
let(:env_config) { HashWithIndifferentAccess.new } | ||
let(:plugin_config) { HashWithIndifferentAccess.new } | ||
|
||
it('returns nothing when no config is present') do | ||
expect(subject[:nic]).to be_nil | ||
end | ||
|
||
it('returns default config in plugin') do | ||
plugin_config[:nic] = 'cage' | ||
|
||
expect(subject[:nic]).to eql('cage') | ||
end | ||
|
||
it('returns config in environment') do | ||
env_config[:nic] = 'cage' | ||
|
||
expect(subject[:nic]).to eql('cage') | ||
end | ||
|
||
it('returns config in project') do | ||
project_config[:nic] = 'cage' | ||
|
||
expect(subject[:nic]).to eql('cage') | ||
end | ||
|
||
it('overrides environment config with plugin config') do | ||
plugin_config[:nic] = 'copolla' | ||
env_config[:nic] = 'cage' | ||
|
||
expect(subject[:nic]).to eql('cage') | ||
end | ||
|
||
it('overrides environment config with project config') do | ||
env_config[:nic] = 'copolla' | ||
project_config[:nic] = 'cage' | ||
|
||
expect(subject[:nic]).to eql('cage') | ||
end | ||
|
||
it('overrides environment and plugin config with project config') do | ||
plugin_config[:nic] = 'kim' | ||
env_config[:nic] = 'copolla' | ||
project_config[:nic] = 'cage' | ||
|
||
expect(subject[:nic]).to eql('cage') | ||
end | ||
end | ||
end |
Oops, something went wrong.