empezar 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +16 -0
- data/Rakefile +1 -0
- data/empezar.gemspec +23 -0
- data/lib/empezar/configuration.rb +13 -0
- data/lib/empezar/exceptions.rb +3 -0
- data/lib/empezar/log.rb +21 -0
- data/lib/empezar/runner.rb +28 -0
- data/lib/empezar/version.rb +3 -0
- data/lib/empezar.rb +9 -0
- data/spec/configuration_spec.rb +14 -0
- data/spec/empezar/configuration_spec.rb +11 -0
- data/spec/empezar/log_spec.rb +15 -0
- data/spec/empezar/runner_spec.rb +73 -0
- data/spec/log_spec.rb +14 -0
- data/spec/runner_spec.rb +14 -0
- data/spec/spec_helper.rb +1 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Xavier Via
|
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,16 @@
|
|
1
|
+
# Empezar
|
2
|
+
|
3
|
+
A simple Ruby library to enforce a convention for configuration, logging and execution
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
gem install empezar
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'empezar'
|
13
|
+
|
14
|
+
Runner.run # Maps config/main.yaml to Configuration as SymbolMatrix
|
15
|
+
# Gets ready Log as a logger in log/main.log
|
16
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/empezar.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'empezar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "empezar"
|
8
|
+
gem.version = Empezar::VERSION
|
9
|
+
gem.authors = ["Xavier Via"]
|
10
|
+
gem.email = ["xavierviacanel@gmail.com"]
|
11
|
+
gem.description = %q{A simple Ruby library to enforce a convention for configuration, logging and execution}
|
12
|
+
gem.summary = %q{A simple Ruby library to enforce a convention for configuration, logging and execution}
|
13
|
+
gem.homepage = "http://github.com/Fetcher/empezar"
|
14
|
+
|
15
|
+
gem.add_dependency 'symbolmatrix'
|
16
|
+
|
17
|
+
gem.add_development_dependency 'rspec'
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($/)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
end
|
data/lib/empezar/log.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Empezar
|
2
|
+
class Log
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
def self.instance
|
6
|
+
@logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.start logger
|
10
|
+
@logger = logger
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Log
|
16
|
+
class << self
|
17
|
+
def method_missing *args
|
18
|
+
Empezar::Log.instance.send *args
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Empezar
|
2
|
+
class Runner
|
3
|
+
def self.run argument = 'config/main.yaml'
|
4
|
+
self.start_logger
|
5
|
+
self.start_configuration argument
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.start_configuration argument
|
9
|
+
unless File.exist? argument
|
10
|
+
raise ConfigurationFileMissingException, "The configuration file is missing from '#{argument}'"
|
11
|
+
end
|
12
|
+
Empezar::Configuration.instance.merge SymbolMatrix.new argument
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.start_logger
|
16
|
+
Dir.mkdir 'log' unless Dir.exist? 'log'
|
17
|
+
Empezar::Log.start Logger.new 'log/main.log', 'daily'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Runner
|
23
|
+
class << self
|
24
|
+
def method_missing *args
|
25
|
+
Empezar::Runner.send *args
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/empezar.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Configuration do
|
4
|
+
it 'should redirect random calls to the instance of Empezar::Configuration' do
|
5
|
+
Empezar::Configuration.instance.should_receive :hola
|
6
|
+
Configuration.hola
|
7
|
+
|
8
|
+
Empezar::Configuration.instance.should_receive :aaaaaaaa
|
9
|
+
Configuration.aaaaaaaa
|
10
|
+
|
11
|
+
Empezar::Configuration.instance.should_receive(:oo=).with "hola"
|
12
|
+
Configuration.oo = "hola"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Empezar::Configuration do
|
4
|
+
it 'should be a Singleton' do
|
5
|
+
Empezar::Configuration.ancestors.should include Singleton
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should inherit from SymbolMatrix' do
|
9
|
+
Empezar::Configuration.superclass.should == SymbolMatrix
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Empezar::Log do
|
4
|
+
it 'should be a Singleton' do
|
5
|
+
Empezar::Log.ancestors.should include Singleton
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#instance' do
|
9
|
+
it 'should be as initialized in the start' do
|
10
|
+
logger_stub = stub 'logger'
|
11
|
+
Empezar::Log.start logger_stub
|
12
|
+
Empezar::Log.instance.should == logger_stub
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Empezar::Runner do
|
4
|
+
describe '.run' do
|
5
|
+
it 'should call start_logger' do
|
6
|
+
Empezar::Runner.stub :start_configuration
|
7
|
+
Empezar::Runner.should_receive(:start_logger)
|
8
|
+
Empezar::Runner.run
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'without argument' do
|
12
|
+
it 'should call start_configuration with config/main.yaml' do
|
13
|
+
Empezar::Runner.stub :start_logger
|
14
|
+
Empezar::Runner.should_receive(:start_configuration).with('config/main.yaml')
|
15
|
+
Empezar::Runner.run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with argument' do
|
20
|
+
it 'should call start_configuration with the argument' do
|
21
|
+
Empezar::Runner.stub :start_logger
|
22
|
+
Empezar::Runner.should_receive(:start_configuration).with('hola')
|
23
|
+
Empezar::Runner.run 'hola'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.start_logger' do
|
29
|
+
it 'should initialize the log as logger pointing to log/main.log, daily' do
|
30
|
+
Dir.should_receive(:exist?).with('log').and_return true
|
31
|
+
demo_logger = stub 'logger'
|
32
|
+
Logger.should_receive(:new).with('log/main.log', 'daily').and_return demo_logger
|
33
|
+
Empezar::Log.should_receive(:start).with demo_logger
|
34
|
+
|
35
|
+
Empezar::Runner.start_logger
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'the dir log does not exist' do
|
39
|
+
it 'should create the dir log' do
|
40
|
+
Dir.should_receive(:exist?).with('log').and_return false
|
41
|
+
Dir.should_receive(:mkdir).with('log')
|
42
|
+
|
43
|
+
demo_logger = stub 'logger'
|
44
|
+
Logger.should_receive(:new).with('log/main.log', 'daily').and_return demo_logger
|
45
|
+
Empezar::Log.should_receive(:start).with demo_logger
|
46
|
+
|
47
|
+
Empezar::Runner.start_logger
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '.start_configuration' do
|
53
|
+
context 'the configuration file exists' do
|
54
|
+
it 'should initialize the configuration with the argument' do
|
55
|
+
File.stub :exist? => true
|
56
|
+
config_stub = stub 'config'
|
57
|
+
SymbolMatrix.should_receive(:new).with('config/main.yaml').and_return config_stub
|
58
|
+
Empezar::Configuration.instance.should_receive(:merge).with(config_stub)
|
59
|
+
|
60
|
+
Empezar::Runner.start_configuration 'config/main.yaml'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'the configuration file is missing' do
|
65
|
+
it 'should raise a relevant error' do
|
66
|
+
File.should_receive(:exist?).with('config/main.yaml').and_return false
|
67
|
+
expect { Empezar::Runner.start_configuration 'config/main.yaml'
|
68
|
+
}.to raise_error Empezar::ConfigurationFileMissingException,
|
69
|
+
"The configuration file is missing from 'config/main.yaml'"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/log_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Log do
|
4
|
+
it 'should redirect random calls to the instance of Empezar::Log' do
|
5
|
+
Empezar::Log.instance.should_receive :hola
|
6
|
+
Log.hola
|
7
|
+
|
8
|
+
Empezar::Log.instance.should_receive :aaaaaaaa
|
9
|
+
Log.aaaaaaaa
|
10
|
+
|
11
|
+
Empezar::Log.instance.should_receive(:oo=).with "hola"
|
12
|
+
Log.oo = "hola"
|
13
|
+
end
|
14
|
+
end
|
data/spec/runner_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Runner do
|
4
|
+
it 'should redirect random calls to Empezar::Runner' do
|
5
|
+
Empezar::Runner.should_receive :hola
|
6
|
+
Runner.hola
|
7
|
+
|
8
|
+
Empezar::Runner.should_receive :aaaaaaaa
|
9
|
+
Runner.aaaaaaaa
|
10
|
+
|
11
|
+
Empezar::Runner.should_receive(:oo=).with "hola"
|
12
|
+
Runner.oo = "hola"
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'empezar'
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: empezar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Xavier Via
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: symbolmatrix
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A simple Ruby library to enforce a convention for configuration, logging
|
47
|
+
and execution
|
48
|
+
email:
|
49
|
+
- xavierviacanel@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- empezar.gemspec
|
60
|
+
- lib/empezar.rb
|
61
|
+
- lib/empezar/configuration.rb
|
62
|
+
- lib/empezar/exceptions.rb
|
63
|
+
- lib/empezar/log.rb
|
64
|
+
- lib/empezar/runner.rb
|
65
|
+
- lib/empezar/version.rb
|
66
|
+
- spec/configuration_spec.rb
|
67
|
+
- spec/empezar/configuration_spec.rb
|
68
|
+
- spec/empezar/log_spec.rb
|
69
|
+
- spec/empezar/runner_spec.rb
|
70
|
+
- spec/log_spec.rb
|
71
|
+
- spec/runner_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: http://github.com/Fetcher/empezar
|
74
|
+
licenses: []
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.24
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: A simple Ruby library to enforce a convention for configuration, logging
|
97
|
+
and execution
|
98
|
+
test_files:
|
99
|
+
- spec/configuration_spec.rb
|
100
|
+
- spec/empezar/configuration_spec.rb
|
101
|
+
- spec/empezar/log_spec.rb
|
102
|
+
- spec/empezar/runner_spec.rb
|
103
|
+
- spec/log_spec.rb
|
104
|
+
- spec/runner_spec.rb
|
105
|
+
- spec/spec_helper.rb
|