From 0cf68e271439025d51d1147145c1c0f14d214226 Mon Sep 17 00:00:00 2001 From: Dan Neumann Date: Fri, 8 Feb 2013 01:56:12 -0600 Subject: [PATCH] Extracted default value initializers. --- lib/discourse_plugin_registry.rb | 32 ++++++++++++------- .../discourse_plugin_registry_spec.rb | 21 ++++++++++++ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/lib/discourse_plugin_registry.rb b/lib/discourse_plugin_registry.rb index a56862a67e9..8f7abca4c8d 100644 --- a/lib/discourse_plugin_registry.rb +++ b/lib/discourse_plugin_registry.rb @@ -9,10 +9,21 @@ class DiscoursePluginRegistry attr_accessor :stylesheets end - def register_js(filename, options={}) - self.class.javascripts ||= Set.new - self.class.server_side_javascripts ||= Set.new + # Default accessor values + # + def self.stylesheets + @stylesheets ||= Set.new + end + + def self.javascripts + @javascripts ||= Set.new + end + + def self.server_side_javascripts + @server_side_javascripts ||= Set.new + end + def register_js(filename, options={}) # If we have a server side option, add that too. self.class.server_side_javascripts << options[:server_side] if options[:server_side].present? @@ -20,12 +31,11 @@ class DiscoursePluginRegistry end def register_css(filename) - self.class.stylesheets ||= Set.new self.class.stylesheets << filename end def stylesheets - self.class.stylesheets || Set.new + self.class.stylesheets end def register_archetype(name, options={}) @@ -33,17 +43,17 @@ class DiscoursePluginRegistry end def server_side_javascripts - self.class.javascripts || Set.new + self.class.javascripts end def javascripts - self.class.javascripts || Set.new + self.class.javascripts end def self.clear - self.stylesheets = Set.new - self.server_side_javascripts = Set.new - self.javascripts = Set.new + self.stylesheets = nil + self.server_side_javascripts = nil + self.javascripts = nil end def self.setup(plugin_class) @@ -52,6 +62,4 @@ class DiscoursePluginRegistry plugin.setup end - - end diff --git a/spec/components/discourse_plugin_registry_spec.rb b/spec/components/discourse_plugin_registry_spec.rb index fe064e6bced..ea2ad312ca5 100644 --- a/spec/components/discourse_plugin_registry_spec.rb +++ b/spec/components/discourse_plugin_registry_spec.rb @@ -4,6 +4,27 @@ require 'discourse_plugin_registry' describe DiscoursePluginRegistry do let(:registry) { DiscoursePluginRegistry.new } + + context '#stylesheets' do + it 'defaults to an empty Set' do + DiscoursePluginRegistry.stylesheets = nil + DiscoursePluginRegistry.stylesheets.should == Set.new + end + end + + context '#javascripts' do + it 'defaults to an empty Set' do + DiscoursePluginRegistry.javascripts = nil + DiscoursePluginRegistry.javascripts.should == Set.new + end + end + + context '#server_side_javascripts' do + it 'defaults to an empty Set' do + DiscoursePluginRegistry.server_side_javascripts = nil + DiscoursePluginRegistry.server_side_javascripts.should == Set.new + end + end context '.register_css' do before do