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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3536fb1f6c5d346acc03f943b92c63b346120f20
4
- data.tar.gz: 6b4c09125ad8176a5307fb3c94133e54125dbf74
3
+ metadata.gz: 8666bfac9f1c149ca9e9047aae66854ef27cf2db
4
+ data.tar.gz: d7e4c10ef4ad138c955f1620237d5e235ce49310
5
5
  SHA512:
6
- metadata.gz: ea4c1b5c58da055e06312f7f3bf8644af65adf86379e2dd14c453aded959882c788ffb2717d2055f76be1a4ddf58d74b831d42e32e2dce8b9fa5fc602f9c86c5
7
- data.tar.gz: e68af67c774036db313d4355635d77cff123c9565fd6b0635aaf464fe615771ae3f6f9a26b73dfd5853a12bbe77eb615f2d48fd9d969acaebd306bd30ad7509a
6
+ metadata.gz: a1d3fcf4f7c99f5bce312e443ccb02185f018c3c198d9527108d1f2bf71aee134acf534731f865c11cc5a709ee5c532eae749bd86eca11bd51a3f814a7a52345
7
+ data.tar.gz: 8476140aafd89e7b926e40d07cb5d5bc847b6c770ebfb9e10abd26be2b0e6d717f65092af0d9dafbbcaab644565d8d40ce662f943b86c48c6668db39ecb21925
data/bin/constantizer ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require 'constantizer/tasks/all'
3
+
4
+ args = ARGV.dup
5
+ command = args.shift.strip rescue nil
6
+ options = ARGV[1..-1]
7
+
8
+ Rake::Task["constantizer:#{command}"].invoke
@@ -0,0 +1,9 @@
1
+ module Constantizer
2
+ class Configuration
3
+ attr_accessor :directory
4
+
5
+ def initialize
6
+ @directory = File.join('config', 'constants')
7
+ end
8
+ end
9
+ end
@@ -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, 'constants'))
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
- # Rack middleware the reloads RailsConfig on every request (only use in dev mode)
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
@@ -0,0 +1,4 @@
1
+ CURRENCIES:
2
+ - USD
3
+ - EUR
4
+ DEFAULT_CURRENCY: <%= CURRENCIES.first %>
@@ -1,3 +1,3 @@
1
1
  module Constantizer
2
- VERSION = "1.0.0"
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/constantizer.rb CHANGED
@@ -1,14 +1,29 @@
1
- require "constantizer/version"
2
- require "constantizer/integration/sinatra"
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.load_file(file).each { |k, v| Object.const_set k, v } }
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.0.0
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-23 00:00:00.000000000 Z
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.2.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: