envvy 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a8c9b57ae7afb83cfdd4cbb25cc1fa50a324604
4
- data.tar.gz: fbbe6f6c3cc54dae2478bcd9d6927a4aa9ad8c67
3
+ metadata.gz: d3fa08ec3c434f18e06a89d6c8a9d59d53170f6b
4
+ data.tar.gz: a30f7891b0b24938d6969af9f33e5b8c076b9f59
5
5
  SHA512:
6
- metadata.gz: c30f85e71c3b90c76e44b19ccfddb7c407156ce1a3aca974b408b32652463b9d496c79719a9bbb100f24ce0dcebef191335a2e0b055ea59458f56b29dc89b8b2
7
- data.tar.gz: 662814e482c2a093f1ac56eb61223d92009340bcc6bc7b0b1c2ed52e7ee02d7d143f2fa97d9e9d31e04e65c27574df1415825341e32a353e402132be460cc713
6
+ metadata.gz: 4647ef7630bae61bb21709317f24611e0215c36b63adc5f46d817764dd6d49697cf9c467e03d2d6c5bd31c83d93349107354df7b4a5fb9cfe1e75bb6b953ba84
7
+ data.tar.gz: d6b7ed27ae08359dc4ce33a15fbc5e6af38d15883ccdaef949901628c28a0b8e004216d440c3b11f2da7572af79f81cc994e55c42d12965b75ee367cdd7d177b
data/.gitignore CHANGED
@@ -18,3 +18,5 @@ test/dummy_app/log/*.log
18
18
  test/dummy_app/tmp/
19
19
  test/dummy_app/.sass-cache
20
20
 
21
+ *.gem
22
+
data/lib/envvy.rb CHANGED
@@ -1,19 +1,7 @@
1
1
  require "envvy/version"
2
- require "envvy/railtie"
3
2
  require "envvy/js"
3
+ require "envvy/engine"
4
4
 
5
5
  module Envvy
6
- class << self
7
6
 
8
- def register_engine
9
- require "envvy/engine"
10
- end
11
-
12
- def get arg
13
- Railtie.get arg
14
- end
15
- end
16
-
17
-
18
- Envvy.register_engine
19
7
  end
data/lib/envvy/engine.rb CHANGED
@@ -1,10 +1,66 @@
1
+ require 'yaml'
2
+
1
3
  module Envvy
4
+ class Engine < Rails::Engine
5
+ attr_accessor :env
6
+
7
+ class << self
8
+ attr_accessor :config_path
2
9
 
3
- class Engine < ::Rails::Engine
4
- initializer 'env-loader.precompile' do |app|
10
+ def config_path
11
+ @config_path || File.join(Rails.root, "config", "env_vars.yml")
12
+ end
13
+ end
14
+
15
+ initializer "env-loader.precompile" do |app|
5
16
  app.config.assets.paths << root.join('assets', 'javascripts').to_s
6
17
  end
7
- end
8
18
 
19
+ initializer "envvy.register_preprocessor", :after => "sprockets.environment" do
20
+ Rails.application.assets.register_preprocessor "application/javascript", :"js_env" do |context, source|
21
+ if context.logical_path == "js_env" && File.exist?(self.class.config_path)
22
+ context.depend_on(File.expand_path(self.class.config_path))
23
+ end
24
+ source
25
+ end
26
+ end
27
+
28
+ config.before_initialize do
29
+ self.get("config") do |config|
30
+ config.each do |k, v|
31
+ ENV[k.to_s.upcase] ||= v
32
+ end
33
+ end
34
+ end
35
+
36
+ config.before_configuration do
9
37
 
38
+ set_env self.config_path
39
+
40
+ if Rails.env.development?
41
+ require 'filewatch/watch'
42
+ conf_watcher = FileWatch::Watch.new
43
+ conf_watcher.watch(self.config_path)
44
+
45
+ Thread.new do
46
+ conf_watcher.subscribe(1,5) do |_status, path|
47
+ set_env path
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def set_env file
54
+ self.env = {"js_config" => {}, "config" => {}}
55
+ self.env.merge! YAML.load(File.read(file)) if File.exist?(file)
56
+ end
57
+
58
+ def get(key, &block)
59
+ if block_given?
60
+ yield self.env[key]
61
+ else
62
+ return self.env[key]
63
+ end
64
+ end
65
+ end
10
66
  end
data/lib/envvy/js.rb CHANGED
@@ -3,7 +3,7 @@ module Envvy
3
3
  mattr_accessor :env
4
4
 
5
5
  def self.env
6
- @env ||= Envvy.get("js_config")
6
+ @env ||= Envvy::Engine.get("js_config")
7
7
  end
8
8
  end
9
9
  end
data/lib/envvy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Envvy
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -27,7 +27,4 @@ Dummy::Application.configure do
27
27
  config.assets.debug = true
28
28
 
29
29
  config.eager_load = false
30
-
31
- config.eh_surveillance_policy_identifier = "0020422201"
32
- config.eh_insurance_policy_identifier = "0020422201"
33
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envvy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Balaine
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-16 00:00:00.000000000 Z
12
+ date: 2015-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -139,12 +139,10 @@ files:
139
139
  - README.md
140
140
  - Rakefile
141
141
  - app/assets/javascripts/js_env.js.erb
142
- - envvy-1.0.3.gem
143
142
  - envvy.gemspec
144
143
  - lib/envvy.rb
145
144
  - lib/envvy/engine.rb
146
145
  - lib/envvy/js.rb
147
- - lib/envvy/railtie.rb
148
146
  - lib/envvy/version.rb
149
147
  - test/compilation/js_test.rb
150
148
  - test/dummy_app/Rakefile
data/envvy-1.0.3.gem DELETED
Binary file
data/lib/envvy/railtie.rb DELETED
@@ -1,52 +0,0 @@
1
- require 'yaml'
2
-
3
- module Envvy
4
- class Railtie < Rails::Railtie
5
- attr_accessor :env
6
-
7
- class << self
8
- attr_accessor :config_path
9
-
10
- def config_path
11
- @config_path || File.join(Rails.root, "config", "env_vars.yml")
12
- end
13
- end
14
-
15
- config.before_initialize do
16
- self.get("config") do |config|
17
- config.each do |k, v|
18
- ENV[k.to_s.upcase] = v
19
- end
20
- end
21
- end
22
-
23
- config.before_configuration do
24
-
25
- set_env self.config_path
26
-
27
- if Rails.env.development?
28
- require 'filewatch/watch'
29
- conf_watcher = FileWatch::Watch.new
30
- conf_watcher.watch(self.config_path)
31
-
32
- Thread.new do
33
- conf_watcher.subscribe(1,5) do |status, path|
34
- set_env path
35
- end
36
- end
37
- end
38
- end
39
-
40
- def set_env file
41
- self.env = if File.exist?(file) then YAML.load(File.read(file)) else {"js_config" => {}, "config" => {}} end
42
- end
43
-
44
- def get(key, &block)
45
- if block_given?
46
- yield self.env[key]
47
- else
48
- return self.env[key]
49
- end
50
- end
51
- end
52
- end