ruby-app 0.1.6 → 0.1.7
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.
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/lib/ruby-app/application.rb +26 -2
- data/lib/ruby-app/common_config.rb +35 -14
- data/lib/ruby-app/environment.rb +14 -8
- data/lib/ruby-app/version.rb +1 -1
- data/spec/app_spec.rb +9 -0
- data/spec/test_app/config/config.yml +2 -0
- metadata +106 -104
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
RubyApp
|
2
2
|
=======
|
3
3
|
|
4
|
-
Little ruby application template. For
|
4
|
+
Little ruby application template. For create light ruby apps (daemons, EventMachine-apps, ...).
|
5
5
|
Supports bundler, environments, rails dirs tree.
|
6
6
|
|
7
7
|
$ gem install ruby-app
|
data/lib/ruby-app/application.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
3
|
class Application
|
4
|
+
|
4
5
|
class << self
|
6
|
+
|
5
7
|
def tmp_dir
|
6
8
|
@tmp_dir ||= File.join(root, %w{tmp})
|
7
9
|
end
|
@@ -11,8 +13,26 @@ class Application
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def env
|
14
|
-
@env ||=
|
16
|
+
@env ||= begin
|
17
|
+
env = ENV['APP_ENV'] || ENV['RAILS_ENV']
|
18
|
+
|
19
|
+
# if not specify env, try find file with env config/environment.current
|
20
|
+
# which created this file by a capistrano, by example
|
21
|
+
unless env
|
22
|
+
path = File.join(root, %w{ config environment.current })
|
23
|
+
if File.exists?(path)
|
24
|
+
env = File.read(path)
|
25
|
+
env.strip!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
env = 'development' unless env
|
30
|
+
|
31
|
+
env
|
32
|
+
end
|
15
33
|
end
|
34
|
+
|
35
|
+
alias :environment :env
|
16
36
|
|
17
37
|
def logger
|
18
38
|
@logger ||= begin
|
@@ -38,7 +58,11 @@ class Application
|
|
38
58
|
def initializer_paths
|
39
59
|
@initializer_paths ||= []
|
40
60
|
end
|
61
|
+
|
62
|
+
def bundler_group
|
63
|
+
end
|
64
|
+
|
41
65
|
end
|
42
66
|
end
|
43
67
|
|
44
|
-
|
68
|
+
App = Application unless defined?(App)
|
@@ -8,6 +8,28 @@ class CommonConfig
|
|
8
8
|
s.instance_eval(&block)
|
9
9
|
@@configs.merge!(s.configs)
|
10
10
|
end
|
11
|
+
|
12
|
+
def self.load(config_file, shouldbe = false)
|
13
|
+
if File.exists?(config_file)
|
14
|
+
require 'yaml'
|
15
|
+
|
16
|
+
h = YAML.load_file(config_file)
|
17
|
+
if h.is_a?(Hash)
|
18
|
+
h.symbolize_keys!
|
19
|
+
@@configs.merge!(h)
|
20
|
+
else
|
21
|
+
raise "config should be a Hash, but not #{h.inspect}"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
if shouldbe
|
25
|
+
raise "config file not found, create! #{config_file.inspect}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.save(filename)
|
31
|
+
File.open(filename, 'w'){|f| f.write YAML.dump(@@configs) }
|
32
|
+
end
|
11
33
|
|
12
34
|
class Scope
|
13
35
|
def initialize
|
@@ -21,10 +43,10 @@ class CommonConfig
|
|
21
43
|
def method_missing(name, *params, &block)
|
22
44
|
if name.to_s =~ /_address$/i
|
23
45
|
require 'ostruct'
|
24
|
-
@configs[name] = block || OpenStruct.new(:host => params[0], :port => params[1].to_i)
|
46
|
+
@configs[name.to_sym] = block || OpenStruct.new(:host => params[0], :port => params[1].to_i)
|
25
47
|
else
|
26
48
|
params = params[0] if params.size == 1
|
27
|
-
@configs[name] = block || params
|
49
|
+
@configs[name.to_sym] = block || params
|
28
50
|
end
|
29
51
|
end
|
30
52
|
end
|
@@ -32,20 +54,19 @@ class CommonConfig
|
|
32
54
|
def self.[]=(option, value)
|
33
55
|
@@configs[option.to_sym] = value
|
34
56
|
end
|
35
|
-
|
36
|
-
def self.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
57
|
+
|
58
|
+
def self.has_key?(key)
|
59
|
+
@@configs.key?(key.to_sym)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.try(method)
|
63
|
+
self.send(method) rescue nil
|
43
64
|
end
|
44
65
|
|
45
|
-
def self.method_missing(*args)
|
46
|
-
if
|
47
|
-
res = @@configs[
|
48
|
-
res.is_a?(Proc) ? res.call : res
|
66
|
+
def self.method_missing(name, *args)
|
67
|
+
if has_key?(name)
|
68
|
+
res = @@configs[name.to_sym]
|
69
|
+
res.is_a?(Proc) ? res.call : res
|
49
70
|
else
|
50
71
|
super
|
51
72
|
end
|
data/lib/ruby-app/environment.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
-
#require 'yaml'
|
4
|
-
|
5
3
|
local_root = File.dirname(__FILE__)
|
6
4
|
|
7
5
|
# app from gem
|
@@ -19,8 +17,6 @@ require File.join(local_root, 'default_config')
|
|
19
17
|
# gems from app
|
20
18
|
Bundler.require(:default, App.env.to_sym)
|
21
19
|
|
22
|
-
GC.start
|
23
|
-
|
24
20
|
# AS dependencies
|
25
21
|
require 'active_support/dependencies'
|
26
22
|
require 'active_support/core_ext/numeric/time'
|
@@ -29,6 +25,12 @@ require 'active_support/core_ext/object/blank'
|
|
29
25
|
# load application app
|
30
26
|
require File.join(App.root, %w{lib application})
|
31
27
|
|
28
|
+
# require App.bundler_group if defined
|
29
|
+
Bundler.require(App.bundler_group, "#{App.bundler_group}_#{App.env}") if App.bundler_group
|
30
|
+
|
31
|
+
# for free usless data from bundler and gems
|
32
|
+
GC.start
|
33
|
+
|
32
34
|
unless defined?(Rake)
|
33
35
|
App.logger.info "Loading #{App.name}[#{App.env}] ..."
|
34
36
|
end
|
@@ -36,6 +38,10 @@ end
|
|
36
38
|
# default config from app
|
37
39
|
require File.join(App.root, %w{config config})
|
38
40
|
|
41
|
+
# Load configs from yaml
|
42
|
+
CommonConfig.load(File.join(App.root, %w{config config.yml}))
|
43
|
+
CommonConfig.load(File.join(App.root, ['config', "config.yml.#{App.env}"]))
|
44
|
+
|
39
45
|
# configs from app for env
|
40
46
|
begin
|
41
47
|
require File.join(App.root, %W( config environments #{App.env}))
|
@@ -55,16 +61,16 @@ dirs.each do |a|
|
|
55
61
|
ActiveSupport::Dependencies::autoload_paths << a
|
56
62
|
end
|
57
63
|
|
58
|
-
# load initializers app
|
59
|
-
Dir["#{App.root}/config/initializers/*.rb"].each{ |x| load(x) }
|
60
|
-
|
61
64
|
# load initializers from other gems
|
62
65
|
unless App.initializer_paths.empty?
|
63
66
|
App.initializer_paths.flatten.each do |path|
|
64
67
|
require File.expand_path(path)
|
65
68
|
end
|
66
69
|
end
|
67
|
-
|
70
|
+
|
71
|
+
# load initializers app
|
72
|
+
Dir["#{App.root}/config/initializers/*.rb"].each{ |x| load(x) }
|
73
|
+
|
68
74
|
# first load models app
|
69
75
|
Dir["#{App.root}/app/models/*.rb"].each{ |x| require x }
|
70
76
|
|
data/lib/ruby-app/version.rb
CHANGED
data/spec/app_spec.rb
CHANGED
@@ -28,6 +28,15 @@ describe "RubyApp" do
|
|
28
28
|
App.config.proc_test.should == "bbbccc"
|
29
29
|
end
|
30
30
|
|
31
|
+
it "load config from file config/config.yml" do
|
32
|
+
App.config.file.should == :yml
|
33
|
+
end
|
34
|
+
|
35
|
+
it "safe check parameter in config" do
|
36
|
+
App.config.try(:file).should == :yml
|
37
|
+
App.config.try(:file2).should == nil
|
38
|
+
end
|
39
|
+
|
31
40
|
it "should load extensions" do
|
32
41
|
App.some_gem_method.should == "some gem method"
|
33
42
|
end
|
metadata
CHANGED
@@ -1,115 +1,120 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-app
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 6
|
10
|
-
version: 0.1.6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Makarchev Konstantin
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
type: :runtime
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 3
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
31
|
-
version_requirements: *id001
|
32
|
-
prerelease: false
|
12
|
+
date: 2012-06-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
33
15
|
name: activesupport
|
34
|
-
|
35
|
-
type: :runtime
|
36
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
37
17
|
none: false
|
38
|
-
requirements:
|
39
|
-
- -
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
|
43
|
-
- 0
|
44
|
-
version: "0"
|
45
|
-
version_requirements: *id002
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
46
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
|
47
31
|
name: rake
|
48
|
-
|
49
|
-
type: :runtime
|
50
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
51
33
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
|
57
|
-
- 0
|
58
|
-
version: "0"
|
59
|
-
version_requirements: *id003
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
60
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
|
+
- !ruby/object:Gem::Dependency
|
61
47
|
name: thor
|
62
|
-
|
63
|
-
type: :runtime
|
64
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
65
49
|
none: false
|
66
|
-
requirements:
|
67
|
-
- -
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
70
|
-
|
71
|
-
- 0
|
72
|
-
version: "0"
|
73
|
-
version_requirements: *id004
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
74
55
|
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
75
63
|
name: bundler
|
76
|
-
|
77
|
-
type: :development
|
78
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
79
65
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
|
85
|
-
- 0
|
86
|
-
version: "0"
|
87
|
-
version_requirements: *id005
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
88
71
|
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
89
79
|
name: rspec
|
90
|
-
|
91
|
-
type: :development
|
92
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
93
81
|
none: false
|
94
|
-
requirements:
|
95
|
-
- -
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
|
98
|
-
|
99
|
-
- 0
|
100
|
-
version: "0"
|
101
|
-
version_requirements: *id006
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
102
87
|
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
103
95
|
name: rake
|
104
|
-
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Little ruby application template. For creates light ruby apps (daemons,
|
111
|
+
EventMachine-apps, ...). Supports bundler, environments, rails dirs tree.
|
105
112
|
email: kostya27@gmail.com
|
106
|
-
executables:
|
113
|
+
executables:
|
107
114
|
- ruby-app
|
108
115
|
extensions: []
|
109
|
-
|
110
116
|
extra_rdoc_files: []
|
111
|
-
|
112
|
-
files:
|
117
|
+
files:
|
113
118
|
- .gitignore
|
114
119
|
- Gemfile
|
115
120
|
- LICENSE
|
@@ -155,6 +160,7 @@ files:
|
|
155
160
|
- spec/test_app/bin/.gitkeep
|
156
161
|
- spec/test_app/config/boot.rb
|
157
162
|
- spec/test_app/config/config.rb
|
163
|
+
- spec/test_app/config/config.yml
|
158
164
|
- spec/test_app/config/environment.rb
|
159
165
|
- spec/test_app/config/environments/development.rb
|
160
166
|
- spec/test_app/config/environments/production.rb
|
@@ -167,36 +173,32 @@ files:
|
|
167
173
|
- spec/test_app/lib/application.rb
|
168
174
|
homepage: http://github.com/kostya/ruby-app
|
169
175
|
licenses: []
|
170
|
-
|
171
176
|
post_install_message:
|
172
177
|
rdoc_options: []
|
173
|
-
|
174
|
-
require_paths:
|
178
|
+
require_paths:
|
175
179
|
- lib
|
176
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
177
181
|
none: false
|
178
|
-
requirements:
|
179
|
-
- -
|
180
|
-
- !ruby/object:Gem::Version
|
181
|
-
|
182
|
-
segments:
|
182
|
+
requirements:
|
183
|
+
- - ! '>='
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
segments:
|
183
187
|
- 0
|
184
|
-
|
185
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
hash: -590066895
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
190
|
none: false
|
187
|
-
requirements:
|
188
|
-
- -
|
189
|
-
- !ruby/object:Gem::Version
|
190
|
-
|
191
|
-
segments:
|
191
|
+
requirements:
|
192
|
+
- - ! '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
segments:
|
192
196
|
- 0
|
193
|
-
|
197
|
+
hash: -590066895
|
194
198
|
requirements: []
|
195
|
-
|
196
199
|
rubyforge_project:
|
197
200
|
rubygems_version: 1.8.24
|
198
201
|
signing_key:
|
199
202
|
specification_version: 3
|
200
203
|
summary: Ruby application template
|
201
204
|
test_files: []
|
202
|
-
|