From fee9d77067925da7e94f568bd921b3aa3034f48d Mon Sep 17 00:00:00 2001 From: Joel AZEMAR Date: Mon, 14 Apr 2014 15:36:18 +0200 Subject: [PATCH] Add configuration --- .gitignore | 4 ++++ README.md | 6 ++++++ bin/publish | 28 ++++++++++++++++++++++++ lib/common.rb | 30 ++++++++++++++++++++++---- lib/locomotive/common/configuration.rb | 13 +++++++++++ lib/locomotive/common/exception.rb | 21 ++++++++---------- lib/locomotive/common/notifier.rb | 11 ++++++++++ spec/locomotive/exception_spec.rb | 2 +- 8 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 .gitignore create mode 100755 bin/publish create mode 100644 lib/locomotive/common/configuration.rb create mode 100644 lib/locomotive/common/notifier.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b8b3ab --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.bundle +.ruby-* + +*.gem diff --git a/README.md b/README.md index 3e2bd78..e1ec540 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,12 @@ Or install it yourself as: $ gem install locomotivecms_common +## Configuration + + Locomotive::Common.configure do |config| + config.notifier = Locomotive::Common::Logger.setup(File.join(File.expand_path(File.dirname(__FILE__)), 'log', 'locomotivecms.log')) + end + ## Usage TODO: Write usage instructions here diff --git a/bin/publish b/bin/publish new file mode 100755 index 0000000..f615405 --- /dev/null +++ b/bin/publish @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby + +require_relative '../lib/common' + +# bin/publish + +class Publish + + def start version, rvm=false + system "rvm use #{rvm}" + + system "bundle && bundle exec rspec" + system "gem build locomotivecms_common.gemspec" + system "git tag -a v#{Locomotive::Common::VERSION} -m 'version #{Locomotive::Common::VERSION}'" + system "git push --tags" + system "gem push locomotivecms_common-#{Locomotive::Common::VERSION}.gem" + system "git push origin master" + end + +end + +if ARGV.length != 1 # or !ARGV[0].match(/\d{1,3}.\d{1,3}.\d{1,3}/) + puts 'HELP: ' + puts '$ bin/publish [ruby-2.1.1@common]' + exit 0 +end + +Publish.new.start ARGV[0] \ No newline at end of file diff --git a/lib/common.rb b/lib/common.rb index d14827c..a22db7c 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -1,9 +1,31 @@ require_relative 'locomotive/common/version' require_relative 'locomotive/common/logger' require_relative 'locomotive/common/exception' +require_relative 'locomotive/common/notifier' +require_relative 'locomotive/common/configuration' -# module Locomotive -# module Common -# end -# end \ No newline at end of file +begin + require 'pry' +rescue LoadError +end + +module Locomotive + module Common + class << self + attr_writer :configuration + end + + def self.configuration + @configuration ||= Configuration.new + end + + def self.reset + @configuration = Configuration.new + end + + def self.configure + yield(configuration) + end + end +end \ No newline at end of file diff --git a/lib/locomotive/common/configuration.rb b/lib/locomotive/common/configuration.rb new file mode 100644 index 0000000..2eac8e8 --- /dev/null +++ b/lib/locomotive/common/configuration.rb @@ -0,0 +1,13 @@ +module Locomotive + module Common + + class Configuration + attr_accessor :notifier + + def initialize + @notifier = Locomotive::Common::Notifier.new + end + end + + end +end diff --git a/lib/locomotive/common/exception.rb b/lib/locomotive/common/exception.rb index d610819..b6f927f 100644 --- a/lib/locomotive/common/exception.rb +++ b/lib/locomotive/common/exception.rb @@ -1,28 +1,25 @@ +require 'pry' + module Locomotive module Common - # class Notifier - # - # def method_missing method, *args - # nil - # end - # end - class DefaultException < ::Exception attr_accessor :notifier def initialize(message = nil, parent_exception = nil) - # self.notifier = Locomotive::Common::Notifier.new - self.notifier = Locomotive::Common::Logger.setup('log/locomotivecms.log') + self.notifier = Locomotive::Common.configuration.notifier self.log_backtrace(parent_exception) if parent_exception super(message) init_plugins end def init_plugins - @plugins = [] - ::Plugins.constants.each do |name| - @plugins << ::Plugins.const_get(name).new(self) + begin + @plugins = [] + ::Plugins.constants.each do |name| + @plugins << ::Plugins.const_get(name).new(self) + end + rescue NameError end end diff --git a/lib/locomotive/common/notifier.rb b/lib/locomotive/common/notifier.rb new file mode 100644 index 0000000..4acf28e --- /dev/null +++ b/lib/locomotive/common/notifier.rb @@ -0,0 +1,11 @@ +module Locomotive + module Common + + class Notifier + def method_missing method, *args + nil + end + end + + end +end \ No newline at end of file diff --git a/spec/locomotive/exception_spec.rb b/spec/locomotive/exception_spec.rb index 1d10bf5..72f0ac5 100644 --- a/spec/locomotive/exception_spec.rb +++ b/spec/locomotive/exception_spec.rb @@ -5,7 +5,7 @@ specify do expect do raise Locomotive::Common::DefaultException.new - end.to raise_error(DefaultException) + end.to raise_error(Locomotive::Common::DefaultException) end end \ No newline at end of file