tzispa_config 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c7c13e7064f43f5e43dc54ea4f6918984ca24ea76dd9f2aa92c34feb77c03cb8
4
+ data.tar.gz: 1186683931e28684ffe50310d82e8d51ca08451405dfa66d39254da7599329e1
5
+ SHA512:
6
+ metadata.gz: cb21bc2a1f00123de0f2ff6628e56b57d65e516d6d4e00d465adc289446f7d6dd997a7154860cd03961500c9a2480ae0f8ff6343d50bd6bdd9969cc9711602d3
7
+ data.tar.gz: 2fc291a12d5812aca417a5d9ab3c50145ba8774e72566349126aabbdf9f38cf8072582587ee31be5158c73d0084865454d749d91157ca4a6223054ac2daf9826
@@ -0,0 +1,4 @@
1
+ Tzispa Annotations
2
+
3
+ ## v0.1.0
4
+ - Initial version
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at japinero@area-integral.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Juan Antonio Piñero
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Tzispa::Config
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tzispa_config`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tzispa_config'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tzispa_config
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tzispa_config. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the TzispaAnnotation project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tzispa_config/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ module Tzispa
2
+ module Config
3
+
4
+ autoload :Base, 'tzispa/config/base'
5
+ autoload :Yaml, 'tzispa/config/yaml'
6
+
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ module Tzispa
6
+ module Config
7
+
8
+ class Base < Struct
9
+ def self.parametrize(params)
10
+ new(*params&.keys&.map(&:to_sym)).new(*(params&.values&.map do |v|
11
+ v.is_a?(Hash) ? parametrize(v) : v
12
+ end))
13
+ end
14
+
15
+ def method_missing(m, *args, &block)
16
+ return if respond_to_missing?(m)
17
+ super
18
+ end
19
+
20
+ def respond_to_missing?(_sym, _include_priv)
21
+ true
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tzispa
4
+ module Config
5
+ module Environment
6
+
7
+ RACK_ENV = 'RACK_ENV'
8
+
9
+ TZISPA_ENV = 'TZISPA_ENV'
10
+
11
+ DEVELOPMENT_ENV = 'development'
12
+
13
+ DEFAULT_ENV = 'development'
14
+
15
+ PRODUCTION_ENV = 'deployment'
16
+
17
+ RACK_ENV_DEPLOYMENT = 'deployment'
18
+
19
+ DEFAULT_DOTENV_ENV = '.env.%s'
20
+
21
+ DEFAULT_CONFIG = 'config'
22
+
23
+ TZISPA_HOST = 'TZISPA_HOST'
24
+
25
+ TZISPA_SSL = 'TZISPA_SSL'
26
+
27
+ TZISPA_SERVER_HOST = 'TZISPA_SERVER_HOST'
28
+
29
+ DEFAULT_HOST = 'localhost'
30
+
31
+ TZISPA_PORT = 'TZISPA_PORT'
32
+
33
+ TZISPA_SERVER_PORT = 'TZISPA_SERVER_PORT'
34
+
35
+ DEFAULT_PORT = 9412
36
+
37
+ DEFAULT_RACKUP = 'tzispa.ru'
38
+
39
+ DEFAULT_ENVIRONMENT_CONFIG = 'environment'
40
+
41
+ DEFAULT_DOMAINS_PATH = 'apps'
42
+
43
+ DOMAINS = 'domains'
44
+
45
+ DOMAINS_PATH = 'apps/%s'
46
+
47
+ APPLICATION = 'application'
48
+
49
+ APPLICATION_PATH = 'app'
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tzispa
4
+ module Config
5
+ module Rc
6
+
7
+ DEFAULT_ARCHITECTURE = 'domains'
8
+
9
+ APP_ARCHITECTURE = 'app'
10
+
11
+ ARCHITECTURE_KEY = 'architecture'
12
+
13
+ PROJECT_NAME = 'project'
14
+
15
+ DEFAULT_TEST_SUITE = 'minitest'
16
+
17
+ TEST_KEY = 'test'
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tzispa
4
+ module Config
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'tzispa/config/base'
5
+
6
+ module Tzispa
7
+ module Config
8
+
9
+ class Yaml < Tzispa::Config::Base
10
+ def self.load(filename)
11
+ params = YAML.safe_load(File.open(filename))
12
+ parametrize params
13
+ end
14
+
15
+ def self.save(cfg, filename)
16
+ File.open(filename, 'w') do |f|
17
+ f.write cfg.to_yaml
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dotenv'
4
+
5
+ module Tzispa
6
+
7
+ class Env
8
+ def initialize(env: ENV)
9
+ @env = env
10
+ end
11
+
12
+ def [](key)
13
+ @env[key]
14
+ end
15
+
16
+ def []=(key, value)
17
+ @env[key] = value
18
+ end
19
+
20
+ def key?(key)
21
+ @env.key? key
22
+ end
23
+
24
+ def load!(path)
25
+ return unless defined?(Dotenv)
26
+
27
+ contents = ::File.open(path, 'rb:bom|utf-8', &:read)
28
+ parsed = Dotenv::Parser.call(contents)
29
+
30
+ parsed.each do |k, v|
31
+ next if @env.key?(k)
32
+ @env[k] = v
33
+ end
34
+ nil
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,205 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'singleton'
5
+ require 'tzispa/env'
6
+ require 'tzispa/tzisparc'
7
+ require 'tzispa_utils'
8
+ require 'tzispa/config/environment'
9
+
10
+ module Tzispa
11
+
12
+ class Environment
13
+ include Singleton
14
+ include Tzispa::Config::Environment
15
+ using Tzispa::Utils::TzHash
16
+
17
+ LOCK = Mutex.new
18
+
19
+ # rubocop:disable Style/ClassVars
20
+ @@opts = {}
21
+
22
+ def initialize
23
+ @env = Tzispa::Env.new(env: @@opts.delete(:env) || ENV)
24
+ @options = Tzispa::Tzisparc.new(root).options
25
+ @options.merge! @@opts.clone.symbolize!
26
+ LOCK.synchronize { set_env_vars! }
27
+ end
28
+
29
+ class << self
30
+ def opts=(hash)
31
+ @@opts = hash.to_h.dup
32
+ end
33
+
34
+ def [](key)
35
+ instance[key]
36
+ end
37
+
38
+ def method_missing(name, *args, &block)
39
+ if instance.respond_to? name
40
+ instance.send name, *args, &block
41
+ elsif instance.key? ekup = name.to_s.upcase
42
+ instance[ekup]
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ def respond_to_missing?(name, _include_priv)
49
+ instance.respond_to?(name) || instance.key?(name.to_s.upcase)
50
+ end
51
+ end
52
+ # rubocop:enable Style/ClassVars
53
+
54
+ def [](key)
55
+ @env[key]
56
+ end
57
+
58
+ def key?(key)
59
+ @env.key? key
60
+ end
61
+
62
+ def environment
63
+ @environment ||= env[TZISPA_ENV] || rack_env || DEFAULT_ENV
64
+ end
65
+
66
+ def development?
67
+ environment == DEVELOPMENT_ENV
68
+ end
69
+
70
+ def code_reloading?
71
+ development?
72
+ end
73
+
74
+ def environment?(*names)
75
+ names.map(&:to_s).include?(environment)
76
+ end
77
+
78
+ def bundler_groups
79
+ [:default, environment.to_sym]
80
+ end
81
+
82
+ def root
83
+ @root ||= Pathname.new(Dir.pwd)
84
+ end
85
+
86
+ def config
87
+ @config ||= root.join(@options.fetch(:config) { DEFAULT_CONFIG })
88
+ end
89
+
90
+ def project_name
91
+ @options.fetch(:project)
92
+ end
93
+
94
+ def architecture
95
+ @options.fetch(:architecture) do
96
+ warn "Tzispa architecture unknown: see `.tzisparc'"
97
+ exit 1
98
+ end
99
+ end
100
+
101
+ def apps_path
102
+ @options.fetch(:path) do
103
+ case architecture
104
+ when DOMAINS
105
+ DOMAINS_PATH
106
+ when APPLICATION
107
+ APPLICATION_PATH
108
+ end
109
+ end
110
+ end
111
+
112
+ def host
113
+ @host ||= @options.fetch(:host) do
114
+ env[TZISPA_HOST] || DEFAULT_HOST
115
+ end
116
+ end
117
+
118
+ def server_host
119
+ @server_host ||= @options.fetch(:server_host) do
120
+ env[TZISPA_SERVER_HOST] || host
121
+ end
122
+ end
123
+
124
+ def port
125
+ @port ||= @options.fetch(:port) do
126
+ env[TZISPA_PORT] || DEFAULT_PORT
127
+ end.to_i
128
+ end
129
+
130
+ def server_port
131
+ @server_port ||= @options.fetch(:server_port) do
132
+ env[TZISPA_SERVER_PORT] || port
133
+ end.to_i
134
+ end
135
+
136
+ def uri_port
137
+ if ssl?
138
+ ":#{port}" unless port == 443
139
+ else
140
+ ":#{port}" unless port == 80
141
+ end
142
+ end
143
+
144
+ def domains_path
145
+ @domains_path ||= @options.fetch(:domains_path) do
146
+ env[DOMAINS_PATH] || DEFAULT_DOMAINS_PATH
147
+ end
148
+ end
149
+
150
+ def default_port?
151
+ port == DEFAULT_PORT
152
+ end
153
+
154
+ def ssl?
155
+ env[TZISPA_SSL] == 'yes'
156
+ end
157
+
158
+ def rackup
159
+ root.join(@options.fetch(:rackup) { DEFAULT_RACKUP })
160
+ end
161
+
162
+ def daemonize?
163
+ @options.key?(:daemonize) && @options.fetch(:daemonize)
164
+ end
165
+
166
+ def to_options
167
+ @options.to_h.merge(
168
+ environment: environment,
169
+ apps_path: apps_path,
170
+ rackup: rackup,
171
+ host: server_host,
172
+ port: server_port
173
+ )
174
+ end
175
+
176
+ private
177
+
178
+ attr_reader :env
179
+
180
+ def set_env_vars!
181
+ set_application_env_vars!
182
+ set_tzispa_env_vars!
183
+ end
184
+
185
+ def set_tzispa_env_vars!
186
+ env[TZISPA_ENV] = env[RACK_ENV] = environment
187
+ env[TZISPA_HOST] = host
188
+ env[TZISPA_PORT] = port.to_s
189
+ end
190
+
191
+ def set_application_env_vars!
192
+ dotenv = root.join(DEFAULT_DOTENV_ENV % environment)
193
+ env.load!(dotenv) if dotenv.exist?
194
+ end
195
+
196
+ def rack_env
197
+ case env[RACK_ENV]
198
+ when RACK_ENV_DEPLOYMENT
199
+ PRODUCTION_ENV
200
+ else
201
+ env[RACK_ENV]
202
+ end
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'tzispa_utils'
5
+ require 'tzispa/config/rc'
6
+
7
+ module Tzispa
8
+
9
+ class Tzisparc
10
+ using Tzispa::Utils::TzHash
11
+
12
+ include Tzispa::Config::Rc
13
+
14
+ FILE_NAME = '.tzisparc'
15
+
16
+ SEPARATOR = '='
17
+
18
+ def initialize(root)
19
+ @root = root
20
+ end
21
+
22
+ def options
23
+ @options ||= default_options.merge(file_options).symbolize!
24
+ end
25
+
26
+ def default_options
27
+ @default_options ||= { ARCHITECTURE_KEY => DEFAULT_ARCHITECTURE,
28
+ PROJECT_NAME => project_name,
29
+ TEST_KEY => DEFAULT_TEST_SUITE }
30
+ end
31
+
32
+ def exists?
33
+ path_file.exist?
34
+ end
35
+
36
+ def generate
37
+ File.open(path_file, 'w') do |file|
38
+ default_options.each { |k, v| file.puts("#{k}#{SEPARATOR}#{v}") }
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def file_options
45
+ exists? ? parse_file(path_file) : {}
46
+ end
47
+
48
+ def parse_file(path)
49
+ {}.tap do |hash|
50
+ File.readlines(path).each do |line|
51
+ key, value = line.split(SEPARATOR)
52
+ hash[key] = value.strip
53
+ end
54
+ end
55
+ end
56
+
57
+ def path_file
58
+ @root.join FILE_NAME
59
+ end
60
+
61
+ def project_name
62
+ ::File.basename(@root)
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,11 @@
1
+ module Tzispa
2
+
3
+ autoload :Environment, 'tzispa/environment'
4
+
5
+ module Config
6
+
7
+ require 'tzispa/config/version'
8
+ require 'tzispa/config'
9
+
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tzispa_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Antonio Piñero
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tzispa_utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - japinero@area-integral.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - CODE_OF_CONDUCT.md
64
+ - LICENSE.txt
65
+ - README.md
66
+ - lib/tzispa/config.rb
67
+ - lib/tzispa/config/base.rb
68
+ - lib/tzispa/config/environment.rb
69
+ - lib/tzispa/config/rc.rb
70
+ - lib/tzispa/config/version.rb
71
+ - lib/tzispa/config/yaml.rb
72
+ - lib/tzispa/env.rb
73
+ - lib/tzispa/environment.rb
74
+ - lib/tzispa/tzisparc.rb
75
+ - lib/tzispa_config.rb
76
+ homepage: https://github.com/japiber/tzispa_config
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ - test
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.7.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: configuration management
101
+ test_files: []