biran 0.1.6 → 0.1.7

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
- SHA1:
3
- metadata.gz: cbbf6682aad11d3d9954df25555baa94be850624
4
- data.tar.gz: 39016c642ec0bce21ca5394275271cd7409632cb
2
+ SHA256:
3
+ metadata.gz: a67e7f787cbdfa09727e1214e5668cfc20ca239a6765c538b46884f70436cb10
4
+ data.tar.gz: c48aaf4d46a5a7a1130a14191113ed9db8ec9e8cbac2d71b6e1f74548fd5db32
5
5
  SHA512:
6
- metadata.gz: 2379b8246e3690e8851d5204a5d85a2e6bbcdbc7c154e6222aec125232245586e59ac1818a8ac9ffcf576be8be46c0903dc5ab46d098749b97127cba2a29fd14
7
- data.tar.gz: 670cebdc1b49959dc578e142d47b16ceb53f022bc7f08cf52b71a4853cdf1ac6c4acacc4fe6c9684550ffeee476eb01a1bf792c1bee2cb5fdfe19f13322fded8
6
+ metadata.gz: c878c531325e65bf3d0ec59b7d5b9b2f41921165d4390839c24c5aa78b94b654ab9af45934e0d3242a5031bc19ba7a9afc7e3be294acb14b141e69c438a01c8a
7
+ data.tar.gz: 185b07e2b09bd9fd2d0f666b814a9bb6ba8f5bd0c1e8943031d98cd8bb1fae588d12e59edcba4879df95c120e62a0f208153370621b54e2c0a11c07698ef5f2c
data/README.md CHANGED
@@ -102,6 +102,7 @@ the list of things you can configure are:
102
102
  :bindings,
103
103
  :app_setup_blocks,
104
104
  :files_to_generate
105
+ :vhost_public_dirname
105
106
  ```
106
107
  ## Options
107
108
  ### config_filename
@@ -226,9 +227,18 @@ defaults: &defaults
226
227
  ### app_env
227
228
  **Type: string
228
229
  Default: Rails.env if rails or ‘development’ in non rails
229
- Availble in: config file, initializer**
230
+ Availble in: environment, initializer, instance**
230
231
 
231
- Generally not needed to specify unless you are not using rails or do not want to use `Rails.env` for lookups in config blocks.
232
+ Generally not needed to specify unless you are not using rails or do not want to use `Rails.env` for lookups in config blocks.
233
+ You can set the app_env during instance creation by passing an environment string.
234
+ The following example will use the default or any of the built in environment vairables(BIRAN_APP_ENV, RACK_ENV, RAILS_ENV) or fall back to default.
235
+ ```
236
+ config = Biran::Configurinator.new
237
+ ```
238
+ If you need to specify the environment on the instance directly, you can do the following to create a staging config object independent of the other app_env settings:
239
+ ```
240
+ config = Biran::Configurinator.new(env: ‘staging)
241
+ ```
232
242
 
233
243
  ### bindings
234
244
  **Type: array
@@ -276,7 +286,8 @@ Default:**
276
286
  **Available in: config file, initializer**
277
287
 
278
288
  This config option defines which files you want to be available to generate as part of the config:generate task. Each file listed will get its own task and will be run when `rake config:generate` is run.
279
- The default config will generate `config/vhost.conf` only. By default, all files will be generated in the `config` directory. You can override this in the options.
289
+ The default config will generate `config/vhost.conf` only. By default, all files will be generated in the `config` directory. You can override this in the options by setting an `output_dir` and/or an `output_name` to define the location and the name to be added to the extension.
290
+ NOTE: If you use the `output_name` option, the template name is still pulled from the block name. In the example below, for the reports file, the template name would be `config/_reports.yml.erb` and the block will generate a file in `/srv/app/current/reports` named `user_report.yml`.
280
291
  Basic exmple from `config/app_config.yml`:
281
292
  ```
282
293
  app:
@@ -290,5 +301,16 @@ app:
290
301
  reports:
291
302
  extension: ‘.yml’
292
303
  output_dir: ‘/srv/app/current/reports’
304
+ output_name: ‘user_report’
305
+ ```
306
+ ### vhost_public_dirname
307
+ **Type: string
308
+ Default: 'public'
309
+ Available in: config file, initializer**
310
+
311
+ Used to change the value of the public web directorname for use in the vhost config. Defined in the app block
312
+ ```
313
+ app:
314
+ vhost_public_dirname: 'web'
293
315
  ```
294
316
 
@@ -13,7 +13,7 @@ module Biran
13
13
  def app_env
14
14
  return @app_env if @app_env
15
15
  @app_env = Rails.env if defined? Rails
16
- @app_env ||= 'development'
16
+ @app_env ||= 'development'.freeze
17
17
  end
18
18
 
19
19
  def base_dir
@@ -40,6 +40,10 @@ module Biran
40
40
  @config_dirname ||= 'config'.freeze
41
41
  end
42
42
 
43
+ def vhost_public_dirname
44
+ @vhost_public_dirname ||= 'public'.freeze
45
+ end
46
+
43
47
  def use_capistrano
44
48
  @use_capistrano ||= false
45
49
  end
@@ -13,11 +13,16 @@ module Biran
13
13
  use_capistrano: configuration.use_capistrano,
14
14
  db_config: configuration.db_config,
15
15
  secrets: configuration.secrets,
16
- bindings: configuration.bindings
16
+ bindings: configuration.bindings,
17
+ vhost_public_dirname: configuration.vhost_public_dirname
17
18
  }
18
19
  }
19
20
  end
20
21
 
22
+ def app_env
23
+ ENV['BIRAN_APP_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || configuration.app_env
24
+ end
25
+
21
26
  def app_base
22
27
  @app_base ||= ENV['BIRAN_APP_BASE_PATH'] || app_config_defaults[:app][:base_path] || app_config_defaults[:app][:root_path]
23
28
  end
@@ -45,6 +50,10 @@ module Biran
45
50
  File.join(app_shared_dir, configuration.config_dirname, configuration.local_config_filename)
46
51
  end
47
52
 
53
+ def vhost_public_dirname
54
+ ENV['BIRAN_VHOST_PUBLIC_DIRNAME'] || app_config_defaults[:app][:vhost_public_dirname]
55
+ end
56
+
48
57
  def db_config_override_file
49
58
  File.join(app_shared_dir, configuration.config_dirname, configuration.db_config_filename)
50
59
  end
@@ -4,7 +4,7 @@ module Biran
4
4
 
5
5
  DEFAULT_ENV = 'development'
6
6
 
7
- attr_reader :config, :db_config
7
+ attr_reader :config, :db_config, :env
8
8
 
9
9
  class << self
10
10
  attr_accessor :config
@@ -13,19 +13,10 @@ module Biran
13
13
  self.config ||= Config.instance
14
14
  yield config
15
15
  end
16
-
17
- def env= env
18
- @env = env
19
- end
20
-
21
- def env
22
- return @end if @env
23
- return Rails.env if defined? Rails
24
- DEFAULT_ENV
25
- end
26
16
  end
27
17
 
28
- def initialize
18
+ def initialize(env: nil)
19
+ @env = env || app_env
29
20
  @config = build_app_config
30
21
  end
31
22
 
@@ -39,9 +30,10 @@ module Biran
39
30
  .tap { |files_list| files_list.each(&sanitize_config_files(files_list)) }
40
31
  end
41
32
 
42
- def create(name:, extension:, output_dir: nil)
33
+ def create(name:, extension:, output_dir: nil, output_name: nil)
43
34
  output_dir ||= config_dir
44
- generated_file = ERBConfig.new(filtered_config, name, extension, config_dir, output_dir)
35
+ output_name ||= name
36
+ generated_file = ERBConfig.new(filtered_config, name, extension, config_dir, output_dir, output_name)
45
37
  generated_file.bindings = bindings
46
38
  generated_file.save!
47
39
  end
@@ -49,10 +41,12 @@ module Biran
49
41
  private
50
42
 
51
43
  def build_app_config
44
+ raise 'Environment not set to build the application config' unless @env
52
45
  app_config = {
53
46
  app_root_dir: app_root,
54
47
  app_shared_dir: app_shared_dir,
55
48
  app_base_dir: app_base,
49
+ env: env,
56
50
  local_config_file: local_config_file,
57
51
  secrets_file_path: secrets_file,
58
52
  vhost: config_vhost_dirs
@@ -89,15 +83,15 @@ module Biran
89
83
  config_file_contents = File.read(config_file)
90
84
  config_file_contents = ERB.new(config_file_contents).result
91
85
  config_file_contents = YAML.safe_load(config_file_contents, [], [], true)
92
- config_file_contents[Configurinator.env].deep_symbolize_keys!
86
+ config_file_contents[env].deep_symbolize_keys!
93
87
  rescue Errno::ENOENT
94
88
  raise "Missing config file: #{config_file}"
95
89
  end
96
90
 
97
91
  def config_vhost_dirs
98
92
  {
99
- public_dir: File.join(app_root, 'public'),
100
- shared_dir: app_shared_dir,
93
+ public_dir: File.join(app_root, vhost_public_dirname),
94
+ shared_dir: app_shared_dir.to_s,
101
95
  log_dir: File.join(app_root, 'log'),
102
96
  pids_dir: File.join(app_root, 'tmp', 'pids')
103
97
  }
@@ -0,0 +1,145 @@
1
+ module Biran
2
+ class Configurinator
3
+ include ConfigDefaults
4
+
5
+ DEFAULT_ENV = 'development'
6
+
7
+ attr_reader :config, :db_config
8
+
9
+ class << self
10
+ attr_accessor :config
11
+
12
+ def configure
13
+ self.config ||= Config.instance
14
+ yield config
15
+ end
16
+
17
+ def env= env
18
+ @env = env
19
+ end
20
+ end
21
+
22
+ def env
23
+ return @env if @env
24
+ @env = app_env
25
+ end
26
+
27
+ def initialize
28
+ @config = build_app_config
29
+ end
30
+
31
+ def file_tasks
32
+ files_to_generate.keys
33
+ end
34
+
35
+ def debug_stuff
36
+ puts "app env2 is: #{app_env}"
37
+ puts "instance @env is #{@env}"
38
+ puts "env from method is #{env}"
39
+ puts "rack env is #{ENV['RACK_ENV']}"
40
+ end
41
+
42
+ def files_to_generate
43
+ @files_to_generate ||= config.fetch(:app, {})
44
+ .fetch(:files_to_generate, configuration.files_to_generate)
45
+ .tap { |files_list| files_list.each(&sanitize_config_files(files_list)) }
46
+ end
47
+
48
+ def create(name:, extension:, output_dir: nil)
49
+ output_dir ||= config_dir
50
+ #debug_stuff
51
+ generated_file = ERBConfig.new(filtered_config, name, extension, config_dir, output_dir)
52
+ generated_file.bindings = bindings
53
+ generated_file.save!
54
+ end
55
+
56
+ private
57
+
58
+ def build_app_config
59
+ app_config = {
60
+ app_root_dir: app_root,
61
+ app_shared_dir: app_shared_dir,
62
+ app_base_dir: app_base,
63
+ env: env,
64
+ local_config_file: local_config_file,
65
+ secrets_file_path: secrets_file,
66
+ vhost: config_vhost_dirs
67
+ }
68
+
69
+ app_config.deep_merge! app_config_defaults
70
+ app_config[:secrets] = get_secret_contents(app_config)
71
+ app_config[:db_config] = build_db_config
72
+
73
+ app_config.deep_merge! local_config_file_contents
74
+ end
75
+
76
+ def build_db_config
77
+ default_db_config = base_db_config
78
+ return default_db_config unless File.exist? db_config_override_file
79
+ default_db_config.deep_merge! process_config_file(db_config_override_file)
80
+ end
81
+
82
+ def base_db_config
83
+ return @base_db_config if @base_db_config
84
+ return @base_db_config = {} unless File.exists? default_db_config_file
85
+ @base_db_config ||= process_config_file(default_db_config_file)
86
+ end
87
+
88
+ def app_config_defaults
89
+ return @app_config_defaults if @app_config_defaults
90
+ app_config_file = File.join(configuration.config_dirname, configuration.config_filename)
91
+ app_defaults = app_defaults_init.dup
92
+ config_properties = process_config_file(app_config_file)
93
+ @app_config_defaults = app_defaults.deep_merge! config_properties
94
+ end
95
+
96
+ def process_config_file(config_file)
97
+ config_file_contents = File.read(config_file)
98
+ config_file_contents = ERB.new(config_file_contents).result
99
+ config_file_contents = YAML.safe_load(config_file_contents, [], [], true)
100
+ config_file_contents[env].deep_symbolize_keys!
101
+ rescue Errno::ENOENT
102
+ raise "Missing config file: #{config_file}"
103
+ end
104
+
105
+ def config_vhost_dirs
106
+ {
107
+ public_dir: File.join(app_root, vhost_public_dirname),
108
+ shared_dir: app_shared_dir.to_s,
109
+ log_dir: File.join(app_root, 'log'),
110
+ pids_dir: File.join(app_root, 'tmp', 'pids')
111
+ }
112
+ end
113
+
114
+ def local_config_file_contents
115
+ return @local_config_contents if @local_config_contents
116
+ return @local_config_conents = {} unless File.exists? local_config_file
117
+ @local_config_contents = process_config_file(local_config_file)
118
+ end
119
+
120
+ def get_secret_contents(app_config)
121
+ secrets_file_contents = {}
122
+ if File.exist? app_config[:secrets_file_path]
123
+ secrets_file_contents = process_config_file app_config[:secrets_file_path]
124
+ end
125
+ secrets_file_contents
126
+ end
127
+
128
+ def sanitize_config_files files_list
129
+ lambda do |file, _|
130
+ files_list[file] ||= {extension: ''}
131
+ ext = files_list[file].fetch(:extension, '').strip
132
+ ext.prepend('.') unless ext.start_with?('.') || ext.empty?
133
+ files_list[file][:extension] = ext
134
+ end
135
+ end
136
+
137
+ def filtered_config
138
+ @filtered_config ||= config.except(*configuration.app_setup_blocks)
139
+ end
140
+
141
+ def use_capistrano?
142
+ app_config_defaults[:app][:use_capistrano]
143
+ end
144
+ end
145
+ end
@@ -1,18 +1,19 @@
1
1
  module Biran
2
2
  class ERBConfig
3
- attr_reader :output_dir, :source_dir, :name, :extension, :config
3
+ attr_reader :output_dir, :source_dir, :name, :extension, :config, :output_name
4
4
  attr_accessor :bindings
5
5
 
6
- def initialize(config, name, extension, source, output)
6
+ def initialize(config, name, extension, source, output_dir, output_name)
7
7
  @name = name
8
8
  @extension = extension
9
9
  @config = config
10
10
  @source_dir = source
11
- @output_dir = output
11
+ @output_dir = output_dir
12
+ @output_name = output_name
12
13
  end
13
14
 
14
15
  def save!
15
- File.open(File.join(output_dir, "#{name}#{extension}"), 'w') do |f|
16
+ File.open(File.join(output_dir, "#{output_name}#{extension}"), 'w') do |f|
16
17
  f.print process_erb.result(build_erb_env.call)
17
18
  end
18
19
  end
@@ -26,7 +27,7 @@ module Biran
26
27
 
27
28
  def build_erb_env
28
29
  proc do
29
- @environment = Configurinator.env
30
+ @environment = config[:env]
30
31
  @app_config = config
31
32
 
32
33
  @bindings.each(&assign_instance_vars) unless @bindings.nil?
@@ -1,3 +1,3 @@
1
1
  module Biran
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biran
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - javierg
@@ -10,50 +10,50 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-03-21 00:00:00.000000000 Z
13
+ date: 2019-05-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">="
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 5.0.7
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ">="
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '0'
28
+ version: 5.0.7
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: activesupport
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ">="
33
+ - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '0'
35
+ version: 5.0.7
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ">="
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '0'
42
+ version: 5.0.7
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rails
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">="
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '0'
49
+ version: 5.0.7
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ">="
54
+ - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '0'
56
+ version: 5.0.7
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: bundler
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -125,6 +125,7 @@ files:
125
125
  - lib/biran/config.rb
126
126
  - lib/biran/config_defaults.rb
127
127
  - lib/biran/configurinator.rb
128
+ - lib/biran/configurinator.rb.debug
128
129
  - lib/biran/erb_config.rb
129
130
  - lib/biran/railtie.rb
130
131
  - lib/biran/version.rb
@@ -148,8 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  - !ruby/object:Gem::Version
149
150
  version: '0'
150
151
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 2.5.2.1
152
+ rubygems_version: 3.0.3
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: Helper for generating config generate tasks.