dotcrypt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 973dc2c96ca4ccd4fd8baffcf2267a7ae7895c26fc2d938dc650e4b4e8e0d334
4
+ data.tar.gz: aed7a3189574549ba8dc352a5c7c0891b93d77bc8714b387d4f9e57437163ffd
5
+ SHA512:
6
+ metadata.gz: 825f1b9206ce912718e226cdc4e8ca281fbe29b50002e590b758c052c2de735dc387b0f3b95e46d57042c1724ebf006b10f774ecdc647f1736bb97fde93c9a47
7
+ data.tar.gz: 0edc489acba9372f3025a69862559613c88585ae841d45068dcf49e4637fd0d19c557fc1b2f2b7c3b4630c4175570768b7461648e9b1eac35f73933d25e68456
data/.env.dhall ADDED
@@ -0,0 +1,11 @@
1
+ let some_variable = "some value'"
2
+ in {
3
+ some_string = some_variable,
4
+ some_record = {
5
+ some_string = some_variable,
6
+ some_naturals = [1,2,3],
7
+ some_doubles = [1.2, 2.3],
8
+ some_strings = ["value1", "value2"],
9
+ some_nil = None
10
+ }
11
+ }
data/.overcommit.yml ADDED
@@ -0,0 +1,4 @@
1
+ PreCommit:
2
+ RuboCop:
3
+ enabled: true
4
+ on_warn: fail # Treat all warnings as failures
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,44 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ require:
7
+ - rubocop-performance
8
+ - rubocop-rspec
9
+
10
+ Layout/LineLength:
11
+ Max: 120
12
+ Exclude:
13
+ - spec/**/*_spec.rb
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - spec/**/*_spec.rb
18
+ - "*.gemspec"
19
+
20
+ Metrics/MethodLength:
21
+ Max: 10
22
+
23
+ RSpec/NamedSubject:
24
+ Enabled: false
25
+
26
+ Style/StringLiterals:
27
+ Enabled: true
28
+ EnforcedStyle: double_quotes
29
+
30
+ Style/StringLiteralsInInterpolation:
31
+ Enabled: true
32
+ EnforcedStyle: double_quotes
33
+
34
+ Style/Documentation:
35
+ Enabled: false
36
+
37
+ Style/SymbolArray:
38
+ EnforcedStyle: brackets
39
+
40
+ Style/WordArray:
41
+ EnforcedStyle: brackets
42
+
43
+ Style/ClassAndModuleChildren:
44
+ EnforcedStyle: compact
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at zhulik.gleb@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~> 13.0"
8
+
9
+ gem "rspec", "~> 3.0"
10
+
11
+ gem "rubocop"
12
+ gem "rubocop-performance"
13
+ gem "rubocop-rspec"
14
+
15
+ gem "overcommit"
16
+ gem "solargraph"
data/Gemfile.lock ADDED
@@ -0,0 +1,130 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dotcrypt (0.1.0)
5
+ bootsnap (~> 1.15.0)
6
+ dhall (~> 0.5.0)
7
+ thor (~> 1.2.0)
8
+ zeitwerk (~> 2.6.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ ast (2.4.2)
14
+ backport (1.2.0)
15
+ base32 (0.3.4)
16
+ benchmark (0.2.0)
17
+ bootsnap (1.15.0)
18
+ msgpack (~> 1.2)
19
+ cbor (0.5.9.6)
20
+ childprocess (4.1.0)
21
+ citrus (3.0.2)
22
+ dhall (0.5.5)
23
+ base32 (~> 0.3.2)
24
+ cbor (~> 0.5.9.3)
25
+ citrus (~> 3.0)
26
+ lazy_object (>= 0.0.1, < 0.2.0)
27
+ multihashes (~> 0.2.0)
28
+ promise.rb (~> 0.7.4)
29
+ value_semantics (~> 3.0)
30
+ diff-lcs (1.5.0)
31
+ e2mmap (0.1.0)
32
+ iniparse (1.5.0)
33
+ jaro_winkler (1.5.4)
34
+ json (2.6.2)
35
+ kramdown (2.4.0)
36
+ rexml
37
+ kramdown-parser-gfm (1.1.0)
38
+ kramdown (~> 2.0)
39
+ lazy_object (0.1.0)
40
+ msgpack (1.6.0)
41
+ multicodecs (0.2.1)
42
+ multihashes (0.2.0)
43
+ multicodecs (>= 0.2.0, < 1)
44
+ nokogiri (1.13.10-x86_64-linux)
45
+ racc (~> 1.4)
46
+ overcommit (0.59.1)
47
+ childprocess (>= 0.6.3, < 5)
48
+ iniparse (~> 1.4)
49
+ rexml (~> 3.2)
50
+ parallel (1.22.1)
51
+ parser (3.1.3.0)
52
+ ast (~> 2.4.1)
53
+ promise.rb (0.7.4)
54
+ racc (1.6.2)
55
+ rainbow (3.1.1)
56
+ rake (13.0.6)
57
+ regexp_parser (2.6.1)
58
+ reverse_markdown (2.1.1)
59
+ nokogiri
60
+ rexml (3.2.5)
61
+ rspec (3.12.0)
62
+ rspec-core (~> 3.12.0)
63
+ rspec-expectations (~> 3.12.0)
64
+ rspec-mocks (~> 3.12.0)
65
+ rspec-core (3.12.0)
66
+ rspec-support (~> 3.12.0)
67
+ rspec-expectations (3.12.0)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.12.0)
70
+ rspec-mocks (3.12.0)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.12.0)
73
+ rspec-support (3.12.0)
74
+ rubocop (1.39.0)
75
+ json (~> 2.3)
76
+ parallel (~> 1.10)
77
+ parser (>= 3.1.2.1)
78
+ rainbow (>= 2.2.2, < 4.0)
79
+ regexp_parser (>= 1.8, < 3.0)
80
+ rexml (>= 3.2.5, < 4.0)
81
+ rubocop-ast (>= 1.23.0, < 2.0)
82
+ ruby-progressbar (~> 1.7)
83
+ unicode-display_width (>= 1.4.0, < 3.0)
84
+ rubocop-ast (1.23.0)
85
+ parser (>= 3.1.1.0)
86
+ rubocop-performance (1.15.1)
87
+ rubocop (>= 1.7.0, < 2.0)
88
+ rubocop-ast (>= 0.4.0)
89
+ rubocop-rspec (2.15.0)
90
+ rubocop (~> 1.33)
91
+ ruby-progressbar (1.11.0)
92
+ solargraph (0.47.2)
93
+ backport (~> 1.2)
94
+ benchmark
95
+ bundler (>= 1.17.2)
96
+ diff-lcs (~> 1.4)
97
+ e2mmap
98
+ jaro_winkler (~> 1.5)
99
+ kramdown (~> 2.3)
100
+ kramdown-parser-gfm (~> 1.1)
101
+ parser (~> 3.0)
102
+ reverse_markdown (>= 1.0.5, < 3)
103
+ rubocop (>= 0.52)
104
+ thor (~> 1.0)
105
+ tilt (~> 2.0)
106
+ yard (~> 0.9, >= 0.9.24)
107
+ thor (1.2.1)
108
+ tilt (2.0.11)
109
+ unicode-display_width (2.3.0)
110
+ value_semantics (3.6.1)
111
+ webrick (1.7.0)
112
+ yard (0.9.28)
113
+ webrick (~> 1.7.0)
114
+ zeitwerk (2.6.6)
115
+
116
+ PLATFORMS
117
+ x86_64-linux
118
+
119
+ DEPENDENCIES
120
+ dotcrypt!
121
+ overcommit
122
+ rake (~> 13.0)
123
+ rspec (~> 3.0)
124
+ rubocop
125
+ rubocop-performance
126
+ rubocop-rspec
127
+ solargraph
128
+
129
+ BUNDLED WITH
130
+ 2.4.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Gleb Sinyavskiy
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Dotcrypt
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ 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/dotcrypt`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dotcrypt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/dotcrypt/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the Dotcrypt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dotcrypt/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: [:spec, :rubocop]
data/exe/dotcrypt ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bootsnap"
5
+
6
+ Bootsnap.setup(cache_dir: "/tmp/cache")
7
+
8
+ require "dotcrypt"
9
+
10
+ Dotcrypt::Cli::App.start(ARGV)
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Dotcrypt::Cli::App < Thor
4
+ include Dotcrypt::Cli::Commands::Show
5
+ include Dotcrypt::Cli::Commands::Exec
6
+ include Dotcrypt::Cli::Commands::ENV
7
+
8
+ default_task :env
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dotcrypt::Cli::Commands::ENV
4
+ def self.included(thor)
5
+ thor.class_eval do
6
+ include Dotcrypt::Cli::Commands::Globals
7
+
8
+ desc "env", "prints exports for ennv"
9
+
10
+ def env = Dotcrypt::Cli::Commands::Show::Handler.new(**options.merge(output: :env)).call
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dotcrypt::Cli::Commands::Exec
4
+ def self.included(thor)
5
+ thor.class_eval do
6
+ include Dotcrypt::Cli::Commands::Globals
7
+
8
+ desc "exec COMMAND", "exec command a command with dhall env"
9
+
10
+ def exec(*command) = Handler.new(command, **options).call
11
+ end
12
+ end
13
+
14
+ class Handler
15
+ def initialize(command, **options)
16
+ @command = command
17
+ @options = options
18
+ end
19
+
20
+ def call
21
+ exec(env, *@command)
22
+ end
23
+
24
+ private
25
+
26
+ def env
27
+ @env ||= Dotcrypt::Dhall.load_from(@options[:file]).then do |c|
28
+ # TODO: validate variable names
29
+ Dotcrypt::Flattener.call(c, separator: @options[:separator])
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dotcrypt::Cli::Commands::Globals
4
+ def self.included(thor)
5
+ thor.class_eval do
6
+ option :separator, aliases: :s,
7
+ type: :string,
8
+ default: "_",
9
+ desc: "Separator for flattening"
10
+
11
+ option :file, aliases: :f,
12
+ type: :string,
13
+ default: ".env.dhall",
14
+ desc: "Dhall file to read."
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dotcrypt::Cli::Commands::Show
4
+ def self.included(thor) # rubocop:disable Metrics/MethodLength
5
+ thor.class_eval do
6
+ include Dotcrypt::Cli::Commands::Globals
7
+
8
+ desc "show", "converts a dhall file into various formats"
9
+
10
+ option :output, aliases: :o,
11
+ type: :string,
12
+ enum: Dotcrypt::Serializers::SERIALIZERS.keys.map(&:to_s),
13
+ default: "yaml",
14
+ desc: "Output format."
15
+
16
+ option :flatten, aliases: :l,
17
+ type: :boolean,
18
+ default: false,
19
+ desc: "Whether to flatten the output. Always enabled for `env` format"
20
+
21
+ def show = Handler.new(**options).call
22
+ end
23
+ end
24
+
25
+ class Handler
26
+ def initialize(**options)
27
+ @options = options
28
+ end
29
+
30
+ def call = print(serializer.call(config))
31
+
32
+ private
33
+
34
+ def config
35
+ @config ||= Dotcrypt::Dhall.load_from(@options[:file]).then do |c|
36
+ next Dotcrypt::Flattener.call(c, separator: @options[:separator]) if @options[:flatten]
37
+
38
+ c
39
+ end
40
+ end
41
+
42
+ def serializer = Dotcrypt::Serializers.for(@options[:output])
43
+ end
44
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dotcrypt::CoreExt::Hash
4
+ refine Hash do
5
+ def deep_stringify_keys
6
+ to_h { |k, v| [k.to_s, v.is_a?(Hash) ? v.deep_stringify_keys : v] }
7
+ end
8
+
9
+ def deep_symbolize_keys
10
+ to_h { |k, v| [k.to_sym, v.is_a?(Hash) ? v.deep_symbolize_keys : v] }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dotcrypt::Dhall::AsHash
4
+ refine ::Dhall::Record do
5
+ def as_hash(*)
6
+ to_h.transform_values(&:as_hash)
7
+ end
8
+ end
9
+
10
+ refine ::Dhall::List do
11
+ def as_hash(*)
12
+ to_a.map(&:as_hash)
13
+ end
14
+ end
15
+
16
+ refine ::Dhall::Text do
17
+ def as_hash(*)
18
+ to_s
19
+ end
20
+ end
21
+
22
+ refine ::Dhall::Natural do
23
+ def as_hash(*)
24
+ to_i
25
+ end
26
+ end
27
+
28
+ refine ::Dhall::Double do
29
+ def as_hash(*)
30
+ to_f
31
+ end
32
+ end
33
+
34
+ refine ::Dhall::Builtins::None do
35
+ def as_hash(*)
36
+ nil
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dotcrypt::Dhall
4
+ using Dotcrypt::Dhall::AsHash
5
+
6
+ class << self
7
+ def load(dhall)
8
+ Dhall.load(dhall).sync.as_hash
9
+ end
10
+
11
+ def load_from(file)
12
+ load(File.read(file))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Dotcrypt::Flattener
4
+ SCALARS = [String, Numeric, NilClass].freeze
5
+
6
+ def self.call(...) = new(...).call
7
+
8
+ def initialize(config, prefixes: [], accumulator: {}, separator: "_")
9
+ @config = config
10
+ @prefixes = prefixes
11
+ @accumulator = accumulator
12
+ @separator = separator
13
+ end
14
+
15
+ def call
16
+ case config
17
+ when *SCALARS then save(@config)
18
+ when Hash then config.each { |k, v| self.class.call(v, prefixes: prefixes + [k], accumulator:, separator:) }
19
+ when Array then flatten_array
20
+ else raise TypeError, "unknown type: #{config.class}"
21
+ end
22
+
23
+ accumulator
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :config, :prefixes, :accumulator, :separator
29
+
30
+ def flatten_array
31
+ raise TypeError, "only arrays of scalars are allowed, given: #{config}" unless config.all? { scalar?(_1) }
32
+
33
+ save(config.to_json)
34
+ end
35
+
36
+ def scalar?(value) = SCALARS.any? { value.is_a?(_1) }
37
+
38
+ def path = @prefixes.join(@separator)
39
+
40
+ def save(value) = @accumulator[path] = value
41
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Dotcrypt::Serializers::ENV < Dotcrypt::Serializers::Serializer
4
+ def call
5
+ # TODO: validate variable names
6
+ Dotcrypt::Flattener.call(@config).reduce("") do |result, (k, v)|
7
+ result + (v.nil? ? "" : "export #{k}='#{escape(v)}'\n")
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def escape(val) = val.gsub("'", %q('"'"'))
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Dotcrypt::Serializers::JSON < Dotcrypt::Serializers::Serializer
4
+ def call = JSON.pretty_generate(@config)
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Dotcrypt::Serializers::Serializer
4
+ def self.call(...) = new(...).call
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def call = raise NotImplementedError
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Dotcrypt::Serializers::YAML < Dotcrypt::Serializers::Serializer
4
+ using Dotcrypt::CoreExt::Hash
5
+
6
+ def call = ::YAML.dump(@config.deep_stringify_keys)
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dotcrypt::Serializers
4
+ SERIALIZERS = {
5
+ json: Dotcrypt::Serializers::JSON,
6
+ env: Dotcrypt::Serializers::ENV,
7
+ yaml: Dotcrypt::Serializers::YAML
8
+ }.freeze
9
+
10
+ def self.for(format)
11
+ SERIALIZERS.fetch(format.to_sym)
12
+ rescue KeyError
13
+ raise ArgumentError, "unknown format: '#{format}', supported formats: #{SERIALIZERS.keys}"
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dotcrypt
4
+ VERSION = "0.1.0"
5
+ end
data/lib/dotcrypt.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "yaml"
5
+
6
+ require "zeitwerk"
7
+ require "dhall"
8
+ require "thor"
9
+
10
+ loader = Zeitwerk::Loader.for_gem
11
+
12
+ loader.inflector.inflect(
13
+ "env" => "ENV",
14
+ "json" => "JSON",
15
+ "yaml" => "YAML"
16
+ )
17
+
18
+ loader.setup
19
+
20
+ class Dotcrypt::Error < StandardError
21
+ # Your code goes here...
22
+ end
data/sig/dotcrypt.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Dotcrypt
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dotcrypt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gleb Sinyavskiy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bootsnap
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.15.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.15.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: dhall
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: zeitwerk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.6.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.6.0
69
+ description: dotcrypt.
70
+ email:
71
+ - zhulik.gleb@gmail.com
72
+ executables:
73
+ - dotcrypt
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".env.dhall"
78
+ - ".overcommit.yml"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - exe/dotcrypt
88
+ - lib/dotcrypt.rb
89
+ - lib/dotcrypt/CLI/app.rb
90
+ - lib/dotcrypt/CLI/commands/env.rb
91
+ - lib/dotcrypt/CLI/commands/exec.rb
92
+ - lib/dotcrypt/CLI/commands/globals.rb
93
+ - lib/dotcrypt/CLI/commands/show.rb
94
+ - lib/dotcrypt/core_ext/hash.rb
95
+ - lib/dotcrypt/dhall.rb
96
+ - lib/dotcrypt/dhall/as_hash.rb
97
+ - lib/dotcrypt/flattener.rb
98
+ - lib/dotcrypt/serializers.rb
99
+ - lib/dotcrypt/serializers/env.rb
100
+ - lib/dotcrypt/serializers/json.rb
101
+ - lib/dotcrypt/serializers/serializer.rb
102
+ - lib/dotcrypt/serializers/yaml.rb
103
+ - lib/dotcrypt/version.rb
104
+ - sig/dotcrypt.rbs
105
+ homepage: https://github.com/zhulik/dotrypt
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ homepage_uri: https://github.com/zhulik/dotrypt
110
+ source_code_uri: https://github.com/zhulik/dotrypt
111
+ changelog_uri: https://github.com/zhulik/dotrypt/releases
112
+ rubygems_mfa_required: 'true'
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 3.1.0
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.4.1
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: dotcrypt.
132
+ test_files: []