utilio 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/environment.rb +3 -2
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +7 -1
- data/VERSION +1 -1
- data/autotest/discover.rb +1 -0
- data/lib/utilio/database.rb +12 -2
- data/lib/utilio/path.rb +1 -1
- data/lib/utilio/security.rb +23 -0
- data/lib/utilio.rb +11 -7
- data/spec/utilio/config/database.yml +6 -0
- data/spec/{data → utilio/data}/path.yml +0 -0
- data/spec/utilio/database_spec.rb +31 -0
- data/spec/{utilio_path_spec.rb → utilio/path_spec.rb} +5 -1
- data/spec/utilio/security_spec.rb +4 -0
- data/utilio.gemspec +12 -8
- metadata +13 -9
- data/spec/data/database.yml +0 -1
- data/spec/utilio_database_spec.rb +0 -15
data/.bundle/environment.rb
CHANGED
@@ -174,11 +174,12 @@ end
|
|
174
174
|
module Bundler
|
175
175
|
ENV_LOADED = true
|
176
176
|
LOCKED_BY = '0.9.26'
|
177
|
-
FINGERPRINT = "
|
177
|
+
FINGERPRINT = "8c71b54c5126769ad4e8cbab25d4e9306f972fd9"
|
178
178
|
HOME = '/Users/bj/.rvm/gems/ruby-1.9.2-rc2/bundler'
|
179
|
-
AUTOREQUIRES = {:development=>[["rspec", false]], :test=>[["rspec", false]]}
|
179
|
+
AUTOREQUIRES = {:default=>[["guid", false]], :development=>[["rspec", false]], :test=>[["rspec", false]]}
|
180
180
|
SPECS = [
|
181
181
|
{:name=>"diff-lcs", :load_paths=>["/Users/bj/.rvm/gems/ruby-1.9.2-rc2/gems/diff-lcs-1.1.2/lib"], :loaded_from=>"/Users/bj/.rvm/gems/ruby-1.9.2-rc2/specifications/diff-lcs-1.1.2.gemspec"},
|
182
|
+
{:name=>"guid", :load_paths=>["/Users/bj/.rvm/gems/ruby-1.9.2-rc2/gems/guid-0.1.1/lib"], :loaded_from=>"/Users/bj/.rvm/gems/ruby-1.9.2-rc2/specifications/guid-0.1.1.gemspec"},
|
182
183
|
{:name=>"rspec-core", :load_paths=>["/Users/bj/.rvm/gems/ruby-1.9.2-rc2/gems/rspec-core-2.0.0.beta.19/lib"], :loaded_from=>"/Users/bj/.rvm/gems/ruby-1.9.2-rc2/specifications/rspec-core-2.0.0.beta.19.gemspec"},
|
183
184
|
{:name=>"rspec-expectations", :load_paths=>["/Users/bj/.rvm/gems/ruby-1.9.2-rc2/gems/rspec-expectations-2.0.0.beta.19/lib"], :loaded_from=>"/Users/bj/.rvm/gems/ruby-1.9.2-rc2/specifications/rspec-expectations-2.0.0.beta.19.gemspec"},
|
184
185
|
{:name=>"rspec-mocks", :load_paths=>["/Users/bj/.rvm/gems/ruby-1.9.2-rc2/gems/rspec-mocks-2.0.0.beta.19/lib"], :loaded_from=>"/Users/bj/.rvm/gems/ruby-1.9.2-rc2/specifications/rspec-mocks-2.0.0.beta.19.gemspec"},
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
---
|
2
|
-
hash:
|
2
|
+
hash: 8c71b54c5126769ad4e8cbab25d4e9306f972fd9
|
3
3
|
sources:
|
4
4
|
- Rubygems:
|
5
5
|
uri: http://gemcutter.org
|
6
6
|
specs:
|
7
7
|
- diff-lcs:
|
8
8
|
version: 1.1.2
|
9
|
+
- guid:
|
10
|
+
version: 0.1.1
|
9
11
|
- rspec-core:
|
10
12
|
version: 2.0.0.beta.19
|
11
13
|
- rspec-expectations:
|
@@ -15,6 +17,10 @@ specs:
|
|
15
17
|
- rspec:
|
16
18
|
version: 2.0.0.beta.19
|
17
19
|
dependencies:
|
20
|
+
guid:
|
21
|
+
version: ">= 0"
|
22
|
+
group:
|
23
|
+
- :default
|
18
24
|
rspec:
|
19
25
|
version: ">= 2.0.0.beta.18"
|
20
26
|
group:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/lib/utilio/database.rb
CHANGED
@@ -3,11 +3,21 @@ require 'utilio/path'
|
|
3
3
|
module Utilio
|
4
4
|
class Database
|
5
5
|
class << self
|
6
|
+
|
7
|
+
DEFAULT_OPTS = {
|
8
|
+
environment: nil,
|
9
|
+
file: 'config/database.yml'
|
10
|
+
}
|
6
11
|
|
7
12
|
# Load the configuration file from your application root
|
8
|
-
def config options={
|
13
|
+
def config options={}
|
14
|
+
options = DEFAULT_OPTS.merge(options)
|
9
15
|
config = Path.yaml_file(options[:file])
|
10
|
-
options[:environment].nil?
|
16
|
+
unless options[:environment].nil? || options[:environment].empty?
|
17
|
+
config[options[:environment]]
|
18
|
+
else
|
19
|
+
config
|
20
|
+
end
|
11
21
|
end
|
12
22
|
|
13
23
|
end
|
data/lib/utilio/path.rb
CHANGED
@@ -13,7 +13,7 @@ module Utilio
|
|
13
13
|
# Get the root path of the application, optionally passing in additional folders to be joined and expanded
|
14
14
|
# e.g. PathUtils.root 'db', 'migrate' # => /path/to/loudmouth/db/migrate
|
15
15
|
def root *folders
|
16
|
-
File.expand_path(File.join(*([app_root, folders].flatten)))
|
16
|
+
File.expand_path(File.join(*([app_root, folders].flatten.uniq.tap{|path| path.delete(nil) })))
|
17
17
|
end
|
18
18
|
|
19
19
|
def app *folders
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'guid'
|
2
|
+
|
3
|
+
module Utilio
|
4
|
+
class Security
|
5
|
+
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def self.hash_string(value)
|
10
|
+
Utils.secure_digest( value )
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.secure_digest(*args)
|
14
|
+
Digest::SHA2.hexdigest(args.flatten.join('--'))
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.generate_guid!
|
18
|
+
Guid.new.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/utilio.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
%w(
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
# %w(
|
2
|
+
# path
|
3
|
+
# database
|
4
|
+
# security
|
5
|
+
# ).each do |file|
|
6
|
+
# require File.expand_path(File.join(File.dirname(__FILE__), 'utilio', File.basename(file, '.rb')))
|
7
|
+
# end
|
8
|
+
#
|
8
9
|
module Utilio
|
10
|
+
autoload :Path, 'utilio/path'
|
11
|
+
autoload :Database, 'utilio/database'
|
12
|
+
autoload :Security, 'utilio/security'
|
9
13
|
end
|
File without changes
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe Utilio::Database do
|
4
|
+
|
5
|
+
let(:config_file) { 'config/database.yml' }
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
Utilio::Path.root = File.dirname(__FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow you to load a db configuration" do
|
12
|
+
lambda {
|
13
|
+
Utilio::Database.config(file: config_file).should_not be_nil
|
14
|
+
}.should_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should default to loading {ROOT}/config/database.yml without an env or file specified" do
|
18
|
+
Utilio::Database.config.should include('development','test','production')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should load the correct env data" do
|
22
|
+
%w( development test production ).each do |env|
|
23
|
+
Utilio::Database.config(environment: env)['database'].should == env
|
24
|
+
end
|
25
|
+
|
26
|
+
%w( bogus not_there ).each do |env|
|
27
|
+
Utilio::Database.config(environment: env).should be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
3
|
describe Utilio::Path do
|
4
4
|
|
@@ -28,6 +28,10 @@ describe Utilio::Path do
|
|
28
28
|
Utilio::Path.root.should == abs_path
|
29
29
|
end
|
30
30
|
|
31
|
+
it "should not concatentate nil values to the root path" do
|
32
|
+
Utilio::Path.root(nil, 'one', nil, nil, 'two').should == File.join(fake_root, 'one', 'two')
|
33
|
+
end
|
34
|
+
|
31
35
|
it "should shortcut paths to an application's app folder" do
|
32
36
|
Utilio::Path.app.should == fake_app
|
33
37
|
end
|
data/utilio.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{utilio}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["BJ Neilsen"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-10}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{bj.neilsen@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,14 +27,17 @@ Gem::Specification.new do |s|
|
|
27
27
|
"README.md",
|
28
28
|
"Rakefile",
|
29
29
|
"VERSION",
|
30
|
+
"autotest/discover.rb",
|
30
31
|
"lib/utilio.rb",
|
31
32
|
"lib/utilio/database.rb",
|
32
33
|
"lib/utilio/path.rb",
|
33
|
-
"
|
34
|
-
"spec/data/path.yml",
|
34
|
+
"lib/utilio/security.rb",
|
35
35
|
"spec/spec_helper.rb",
|
36
|
-
"spec/
|
37
|
-
"spec/
|
36
|
+
"spec/utilio/config/database.yml",
|
37
|
+
"spec/utilio/data/path.yml",
|
38
|
+
"spec/utilio/database_spec.rb",
|
39
|
+
"spec/utilio/path_spec.rb",
|
40
|
+
"spec/utilio/security_spec.rb",
|
38
41
|
"utilio.gemspec"
|
39
42
|
]
|
40
43
|
s.homepage = %q{http://www.rand9.com}
|
@@ -44,8 +47,9 @@ Gem::Specification.new do |s|
|
|
44
47
|
s.summary = %q{A general collection of application utilities for dealing with paths and active_record}
|
45
48
|
s.test_files = [
|
46
49
|
"spec/spec_helper.rb",
|
47
|
-
"spec/
|
48
|
-
"spec/
|
50
|
+
"spec/utilio/database_spec.rb",
|
51
|
+
"spec/utilio/path_spec.rb",
|
52
|
+
"spec/utilio/security_spec.rb"
|
49
53
|
]
|
50
54
|
|
51
55
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- BJ Neilsen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-10 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -52,14 +52,17 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
54
|
- VERSION
|
55
|
+
- autotest/discover.rb
|
55
56
|
- lib/utilio.rb
|
56
57
|
- lib/utilio/database.rb
|
57
58
|
- lib/utilio/path.rb
|
58
|
-
-
|
59
|
-
- spec/data/path.yml
|
59
|
+
- lib/utilio/security.rb
|
60
60
|
- spec/spec_helper.rb
|
61
|
-
- spec/
|
62
|
-
- spec/
|
61
|
+
- spec/utilio/config/database.yml
|
62
|
+
- spec/utilio/data/path.yml
|
63
|
+
- spec/utilio/database_spec.rb
|
64
|
+
- spec/utilio/path_spec.rb
|
65
|
+
- spec/utilio/security_spec.rb
|
63
66
|
- utilio.gemspec
|
64
67
|
has_rdoc: true
|
65
68
|
homepage: http://www.rand9.com
|
@@ -95,5 +98,6 @@ specification_version: 3
|
|
95
98
|
summary: A general collection of application utilities for dealing with paths and active_record
|
96
99
|
test_files:
|
97
100
|
- spec/spec_helper.rb
|
98
|
-
- spec/
|
99
|
-
- spec/
|
101
|
+
- spec/utilio/database_spec.rb
|
102
|
+
- spec/utilio/path_spec.rb
|
103
|
+
- spec/utilio/security_spec.rb
|
data/spec/data/database.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
database: 'test'
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Utilio::Database do
|
4
|
-
|
5
|
-
let(:config_file) { 'data/database.yml' }
|
6
|
-
|
7
|
-
before :all do
|
8
|
-
Utilio::Path.root = File.dirname(__FILE__)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should allow you to load a db configuration" do
|
12
|
-
Utilio::Database.config(file: config_file).should_not be_nil
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|