locomotivecms_common 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6dbfa3ad674f1d0afe144354bdbd6fef81b23b10
4
+ data.tar.gz: 2e34e1e3df1a89fb78a5b3bc1ff704d8d948dfe1
5
+ SHA512:
6
+ metadata.gz: e7b8b82956afa6b02810f4f24bfec3e1cb6c1b0585f616d2d8e1f4dc4dc77c46c21e4b271342d051128f055f38e293874db9bcd86fb86b856e6f9bd338dbd3b5
7
+ data.tar.gz: 7df648ebc689c963decd88034b07333ea53987edd756907d7d16eb1ae2f2d48c734dac82db2cfe6ce07eae9007d4f6479be42e1050fe28b0b2555398b35475e9
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ .ruby-*
3
+
4
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in locomotivecms_common.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ locomotivecms_common (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.2.2)
11
+ rspec (2.14.1)
12
+ rspec-core (~> 2.14.0)
13
+ rspec-expectations (~> 2.14.0)
14
+ rspec-mocks (~> 2.14.0)
15
+ rspec-core (2.14.8)
16
+ rspec-expectations (2.14.5)
17
+ diff-lcs (>= 1.1.3, < 2.0)
18
+ rspec-mocks (2.14.6)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.5)
25
+ locomotivecms_common!
26
+ rake (~> 10.1)
27
+ rspec (~> 2.14)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joel AZEMAR
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # LocomotiveCMS Common
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/common.png)](http://badge.fury.io/rb/locomotivecms_common)
4
+
5
+ [![Code Climate](https://codeclimate.com/github/locomotivecms/common.png)](https://codeclimate.com/github/locomotivecms/common)
6
+
7
+ [![Dependency Status](https://gemnasium.com/locomotivecms/common.png)](https://gemnasium.com/locomotivecms/common)
8
+
9
+ [![Build Status](https://travis-ci.org/locomotivecms/common.png?branch=master)](https://travis-ci.org/locomotivecms/common) (Travis CI)
10
+
11
+ [![Coverage Status](https://coveralls.io/repos/locomotivecms/common/badge.png)](https://coveralls.io/r/locomotivecms/common)
12
+
13
+ # Description
14
+
15
+ Common librairies for locomotive CMS Project
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ gem 'locomotivecms_common'
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install locomotivecms_common
30
+
31
+ ## Configuration
32
+
33
+ Locomotive::Common.configure do |config|
34
+ config.notifier = Locomotive::Common::Logger.setup(File.join(File.expand_path(File.dirname(__FILE__)), 'log', 'locomotivecms.log'))
35
+ end
36
+
37
+ ## Usage
38
+
39
+ TODO: Write usage instructions here
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( http://github.com/<my-github-username>/locomotivecms_common/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'bundler/gem_tasks'
4
+ require 'rake'
5
+ require 'rspec'
6
+ require 'rspec/core/rake_task'
7
+
8
+ require_relative 'lib/common'
9
+
10
+ RSpec::Core::RakeTask.new('spec:all') do |spec|
11
+ spec.pattern = 'spec/**/*_spec.rb'
12
+ end
13
+
14
+ task spec: ['spec:all']
15
+ task default: :spec
data/bin/publish ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/common'
4
+
5
+ # bin/publish
6
+
7
+ class Publish
8
+
9
+ def start
10
+ # if File.exists? '.ruby-version'
11
+ # cmd = <<-CMD
12
+ # rvm use `cat .ruby-version`@`cat .ruby-gemset` --create
13
+ # CMD
14
+ # system cmd
15
+ # end
16
+ # exit 1
17
+
18
+ system "bundle && bundle exec rspec"
19
+ system "gem build locomotivecms_common.gemspec"
20
+ system "git tag -a v#{Locomotive::Common::VERSION} -m 'version #{Locomotive::Common::VERSION}'"
21
+ system "git push --tags"
22
+ system "gem push locomotivecms_common-#{Locomotive::Common::VERSION}.gem"
23
+ system "git push origin master"
24
+ end
25
+
26
+ end
27
+
28
+ Publish.new.start
data/lib/common.rb ADDED
@@ -0,0 +1,31 @@
1
+ require_relative 'locomotive/common/version'
2
+ require_relative 'locomotive/common/logger'
3
+ require_relative 'locomotive/common/exception'
4
+ require_relative 'locomotive/common/notifier'
5
+
6
+ require_relative 'locomotive/common/configuration'
7
+
8
+ begin
9
+ require 'pry'
10
+ rescue LoadError
11
+ end
12
+
13
+ module Locomotive
14
+ module Common
15
+ class << self
16
+ attr_writer :configuration
17
+ end
18
+
19
+ def self.configuration
20
+ @configuration ||= Configuration.new
21
+ end
22
+
23
+ def self.reset
24
+ @configuration = Configuration.new
25
+ end
26
+
27
+ def self.configure
28
+ yield(configuration)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ module Locomotive
2
+ module Common
3
+
4
+ class Configuration
5
+ attr_accessor :notifier
6
+
7
+ def initialize
8
+ @notifier = Locomotive::Common::Notifier.new
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,60 @@
1
+ require 'pry'
2
+
3
+ module Locomotive
4
+ module Common
5
+
6
+ class DefaultException < ::Exception
7
+ attr_accessor :notifier
8
+
9
+ def initialize(message = nil, parent_exception = nil)
10
+ self.notifier = Locomotive::Common.configuration.notifier
11
+ self.log_backtrace(parent_exception) if parent_exception
12
+ super(message)
13
+ init_plugins
14
+ end
15
+
16
+ def init_plugins
17
+ begin
18
+ @plugins = []
19
+ ::Plugins.constants.each do |name|
20
+ @plugins << ::Plugins.const_get(name).new(self)
21
+ end
22
+ rescue NameError
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def log_backtrace(parent_exception)
29
+ full_error_message = "#{parent_exception.message}\n\t"
30
+ full_error_message += parent_exception.backtrace.join("\n\t")
31
+ full_error_message += "\n\n"
32
+
33
+ notifier.fatal full_error_message
34
+ end
35
+ end
36
+
37
+ class RendererException < DefaultException
38
+ attr_accessor :name, :template, :liquid_context
39
+
40
+ def initialize(exception, name, template, liquid_context)
41
+ self.name, self.template, self.liquid_context = name, template, liquid_context
42
+ self.log_page_into_backtrace(exception)
43
+ super(exception.message)
44
+ self.set_backtrace(exception.backtrace)
45
+ end
46
+
47
+ def log_page_into_backtrace(exception)
48
+ line = self.template.line_offset
49
+ line += (exception.respond_to?(:line) ? exception.line || 0 : 0) + 1
50
+ message = "#{self.template.filepath}:#{line}:in `#{self.name}'"
51
+ notifier.fatal "[ERROR] #{exception.message} - #{message}\n".red
52
+ exception.backtrace.unshift message
53
+ end
54
+ end
55
+
56
+ class MounterException < DefaultException; end
57
+ class GeneratorException < DefaultException; end
58
+
59
+ end
60
+ end
@@ -0,0 +1,69 @@
1
+ module Locomotive
2
+ module Common
3
+
4
+ class Logger
5
+
6
+ attr_accessor :logger
7
+
8
+ def initialize
9
+ self.logger = nil
10
+ end
11
+
12
+ # Setup the single instance of the ruby logger.
13
+ #
14
+ # @param[ optional ] [ String ] path The path to the log file, full path with log file name
15
+ # Sample /home/locomotivecms/log/server.log (default: nil => Stdout)
16
+ #
17
+ def setup log_file_full_path=nil
18
+ require 'logger'
19
+
20
+ output = begin
21
+ if log_file_full_path
22
+ log_file_path log_file_full_path
23
+ else
24
+ STDOUT
25
+ end
26
+ end
27
+
28
+ self.logger = ::Logger.new(output).tap do |log|
29
+ log.level = ::Logger::DEBUG
30
+ log.formatter = proc do |severity, datetime, progname, msg|
31
+ "#{msg}\n"
32
+ end
33
+ end
34
+ end
35
+
36
+ def self.instance
37
+ @@instance ||= self.new
38
+ end
39
+
40
+ def self.setup *args
41
+ if args.size > 1
42
+ puts "[DEPRECATION] Logger.setup(path, stdout=false) is deprecated. " \
43
+ "Please use Logger.setup(log_file_full_path) instead, " \
44
+ "like: /home/locomotivecms/log/server.log"
45
+ end
46
+ self.instance.setup args.first
47
+ end
48
+
49
+ class << self
50
+ %w(debug info warn error fatal unknown).each do |name|
51
+ define_method(name) do |message|
52
+ self.instance.logger.send(name.to_sym, message)
53
+ end
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def log_file_path log_file_full_path
60
+ if File.directory? log_file_full_path
61
+ puts "[DEPRECATION] Please use fully log file path like: /home/locomotivecms/log/server.log"
62
+ File.expand_path(File.join(log_file_full_path, 'log', 'locomotivecms.log'))
63
+ else
64
+ log_file_full_path
65
+ end.tap { |path| FileUtils.mkdir_p(File.dirname(path)) }
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,11 @@
1
+ module Locomotive
2
+ module Common
3
+
4
+ class Notifier
5
+ def method_missing method, *args
6
+ nil
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Locomotive
2
+ module Common
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ # # Sample
2
+ #
3
+ # module Plugins
4
+ #
5
+ # class Notifier
6
+ # def initialize receiver
7
+ # receiver.notifier.extend(SilentLogger)
8
+ # end
9
+ #
10
+ # module SilentLogger
11
+ # def fatal(*)
12
+ # nil
13
+ # end
14
+ # end
15
+ # end
16
+ #
17
+ # end
@@ -0,0 +1,24 @@
1
+ require_relative 'lib/common'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'locomotivecms_common'
5
+ spec.version = Locomotive::Common::VERSION
6
+ spec.authors = ['Didier Lafforgue', 'Arnaud Sellenet', 'Joel Azemar']
7
+ spec.email = ['did@locomotivecms.com', 'arnaud@sellenet.fr', 'joel.azemar@gmail.com']
8
+ spec.description = %q{The LocomotiveCMS Common is a shared libraries package}
9
+ spec.summary = %q{The LocomotiveCMS Common is a shared libraries package for all LocomotiveCMS dependencies}
10
+ spec.homepage = 'http://www.locomotivecms.com'
11
+ spec.homepage = 'https://github.com/locomotivecms/common'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.5'
20
+ spec.add_development_dependency 'rake', '~> 10.1'
21
+ spec.add_development_dependency 'rspec', '~> 2.14'
22
+
23
+ spec.required_ruby_version = '~> 2.0'
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Common::DefaultException do
4
+
5
+ specify do
6
+ expect do
7
+ raise Locomotive::Common::DefaultException.new
8
+ end.to raise_error(Locomotive::Common::DefaultException)
9
+ end
10
+
11
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require_relative '../lib/common'
5
+
6
+ RSpec.configure do |config|
7
+ config.filter_run focused: true
8
+ config.run_all_when_everything_filtered = true
9
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locomotivecms_common
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Didier Lafforgue
8
+ - Arnaud Sellenet
9
+ - Joel Azemar
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-04-14 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.5'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.1'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.1'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.14'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '2.14'
57
+ description: The LocomotiveCMS Common is a shared libraries package
58
+ email:
59
+ - did@locomotivecms.com
60
+ - arnaud@sellenet.fr
61
+ - joel.azemar@gmail.com
62
+ executables:
63
+ - publish
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".gitignore"
68
+ - ".travis.yml"
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/publish
75
+ - lib/common.rb
76
+ - lib/locomotive/common/configuration.rb
77
+ - lib/locomotive/common/exception.rb
78
+ - lib/locomotive/common/logger.rb
79
+ - lib/locomotive/common/notifier.rb
80
+ - lib/locomotive/common/version.rb
81
+ - lib/plugins/notifier.rb
82
+ - locomotivecms_common.gemspec
83
+ - spec/locomotive/exception_spec.rb
84
+ - spec/spec_helper.rb
85
+ homepage: https://github.com/locomotivecms/common
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '2.0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.1.11
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: The LocomotiveCMS Common is a shared libraries package for all LocomotiveCMS
109
+ dependencies
110
+ test_files:
111
+ - spec/locomotive/exception_spec.rb
112
+ - spec/spec_helper.rb