constantizer 1.0.0 → 1.1.0
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 +4 -4
- data/bin/constantizer +8 -0
- data/lib/constantizer/configuration.rb +9 -0
- data/lib/constantizer/integration/rails.rb +23 -0
- data/lib/constantizer/integration/sinatra.rb +1 -1
- data/lib/constantizer/rack/reloader.rb +2 -2
- data/lib/constantizer/tasks/all.rb +1 -0
- data/lib/constantizer/tasks/install.rake +18 -0
- data/lib/constantizer/templates/common.yml +4 -0
- data/lib/constantizer/version.rb +1 -1
- data/lib/constantizer.rb +18 -3
- metadata +13 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8666bfac9f1c149ca9e9047aae66854ef27cf2db
|
4
|
+
data.tar.gz: d7e4c10ef4ad138c955f1620237d5e235ce49310
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1d3fcf4f7c99f5bce312e443ccb02185f018c3c198d9527108d1f2bf71aee134acf534731f865c11cc5a709ee5c532eae749bd86eca11bd51a3f814a7a52345
|
7
|
+
data.tar.gz: 8476140aafd89e7b926e40d07cb5d5bc847b6c770ebfb9e10abd26be2b0e6d717f65092af0d9dafbbcaab644565d8d40ce662f943b86c48c6668db39ecb21925
|
data/bin/constantizer
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Constantizer
|
2
|
+
module Integration
|
3
|
+
module Rails
|
4
|
+
if defined?(::Rails::Railtie)
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
# load options after the application initializers are run
|
7
|
+
config.after_initialize do
|
8
|
+
::Constantizer.load!(::Rails.root.join(::Constantizer.configuration.directory))
|
9
|
+
end
|
10
|
+
|
11
|
+
# rails dev environment should reload the options on every request
|
12
|
+
if ::Rails.env.development?
|
13
|
+
initializer :rails_config_reload_on_development do
|
14
|
+
ActionController::Base.class_eval do
|
15
|
+
prepend_before_filter { ::Constantizer.reload! }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -7,7 +7,7 @@ module Constantizer
|
|
7
7
|
module Sinatra
|
8
8
|
def self.registered(app)
|
9
9
|
app.configure do |inner_app|
|
10
|
-
Constantizer.load!(File.join(inner_app.root,
|
10
|
+
Constantizer.load!(File.join(inner_app.root, Constantizer.configuration.directory))
|
11
11
|
|
12
12
|
inner_app.use(Constantizer::Rack::Reloader) if inner_app.development?
|
13
13
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Constantizer
|
2
2
|
module Rack
|
3
|
-
#
|
3
|
+
# rack middleware the reloads Constantizer on every request (only use in dev mode)
|
4
4
|
class Reloader
|
5
5
|
def initialize(app)
|
6
6
|
@app = app
|
@@ -12,4 +12,4 @@ module Constantizer
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path(File.join(File.dirname(__FILE__), 'install.rake'))
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
namespace :constantizer do
|
4
|
+
desc 'Create new constants directory under your app config directory'
|
5
|
+
task :install do
|
6
|
+
constants_dir = File.join('config', 'constants')
|
7
|
+
template_name = 'common.yml'
|
8
|
+
template = File.expand_path(File.join('../../templates', template_name), __FILE__)
|
9
|
+
|
10
|
+
FileUtils.mkdir_p constants_dir
|
11
|
+
|
12
|
+
unless File.exists?(File.join(constants_dir, template_name))
|
13
|
+
FileUtils.cp(template, File.join(constants_dir, template_name))
|
14
|
+
end
|
15
|
+
|
16
|
+
puts 'Done!'
|
17
|
+
end
|
18
|
+
end
|
data/lib/constantizer/version.rb
CHANGED
data/lib/constantizer.rb
CHANGED
@@ -1,14 +1,29 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'constantizer/version'
|
2
|
+
require 'constantizer/configuration'
|
3
|
+
require 'erb'
|
3
4
|
|
4
5
|
module Constantizer
|
5
6
|
|
6
7
|
def self.load!(path)
|
7
8
|
@path = path
|
8
|
-
Dir.glob(File.join(path,'/*.yml')).each { |file| YAML.
|
9
|
+
Dir.glob(File.join(path,'/*.yml')).each { |file| YAML.load(ERB.new(IO.read(file)).result).each { |k, v| Object.const_set k.upcase, v } }
|
9
10
|
end
|
10
11
|
|
11
12
|
def self.reload!
|
12
13
|
load! @path
|
13
14
|
end
|
15
|
+
|
16
|
+
def self.configuration
|
17
|
+
@configuration ||= Configuration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure
|
21
|
+
yield(configuration)
|
22
|
+
end
|
14
23
|
end
|
24
|
+
|
25
|
+
# add rails integration
|
26
|
+
require('constantizer/integration/rails') if defined?(::Rails)
|
27
|
+
|
28
|
+
# add sinatra integration
|
29
|
+
require('constantizer/integration/sinatra') if defined?(::Sinatra)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constantizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Baraa Al-Bourghli
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,14 +43,21 @@ description:
|
|
43
43
|
email:
|
44
44
|
- essam.a0@gmail.com
|
45
45
|
- baraa.bourghli@gmail.com
|
46
|
-
executables:
|
46
|
+
executables:
|
47
|
+
- constantizer
|
47
48
|
extensions: []
|
48
49
|
extra_rdoc_files: []
|
49
50
|
files:
|
50
|
-
- lib/constantizer.rb
|
51
|
+
- lib/constantizer/configuration.rb
|
52
|
+
- lib/constantizer/integration/rails.rb
|
51
53
|
- lib/constantizer/integration/sinatra.rb
|
52
54
|
- lib/constantizer/rack/reloader.rb
|
55
|
+
- lib/constantizer/tasks/all.rb
|
56
|
+
- lib/constantizer/tasks/install.rake
|
57
|
+
- lib/constantizer/templates/common.yml
|
53
58
|
- lib/constantizer/version.rb
|
59
|
+
- lib/constantizer.rb
|
60
|
+
- bin/constantizer
|
54
61
|
homepage: https://github.com/baraabourghli/constantizer
|
55
62
|
licenses:
|
56
63
|
- MIT
|
@@ -71,8 +78,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
78
|
version: '0'
|
72
79
|
requirements: []
|
73
80
|
rubyforge_project:
|
74
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.0.0
|
75
82
|
signing_key:
|
76
83
|
specification_version: 4
|
77
84
|
summary: constantizer is a gem for bulding constants in the app using YAML files
|
78
85
|
test_files: []
|
86
|
+
has_rdoc:
|