Skip to content

Commit

Permalink
Add configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
joel committed Apr 14, 2014
1 parent ec803fb commit fee9d77
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.bundle
.ruby-*

*.gem
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions bin/publish
Original file line number Diff line number Diff line change
@@ -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]
30 changes: 26 additions & 4 deletions lib/common.rb
Original file line number Diff line number Diff line change
@@ -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
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
13 changes: 13 additions & 0 deletions lib/locomotive/common/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Locomotive
module Common

class Configuration
attr_accessor :notifier

def initialize
@notifier = Locomotive::Common::Notifier.new
end
end

end
end
21 changes: 9 additions & 12 deletions lib/locomotive/common/exception.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 11 additions & 0 deletions lib/locomotive/common/notifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Locomotive
module Common

class Notifier
def method_missing method, *args
nil
end
end

end
end
2 changes: 1 addition & 1 deletion spec/locomotive/exception_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fee9d77

Please sign in to comment.