aston 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 825ca0a986669eb04c434775792fadf6f4127f57d82144d4fab9282d2af7e8bd
4
+ data.tar.gz: d6acd466695b6236f494a9b00c784f0b33a7cf61dafedb8d9d2cf1c610d5e811
5
+ SHA512:
6
+ metadata.gz: df8dda9a4fe333ebdc535f7cda0369a30be3478dbbc295f093a08797b9ba9345c7226339fdd10957577c1a9b631aae7caf9f62ae249f290f71dce18663c683d8
7
+ data.tar.gz: b0c056e04628e20b07b9b7346282d55a1e8cef5b250a7751be204d2fb4685f1042e7feb51bf4c58fb98f2e96cf00a431087fce4dbfabed96d1058053466a1909
@@ -0,0 +1,50 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ "main" ]
6
+ pull_request:
7
+ branches: [ "main" ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Test + Build + Publish
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ packages: write
16
+
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - name: Set up Ruby 2.7
20
+ uses: ruby/setup-ruby@v1 # v1.146.0
21
+ with:
22
+ ruby-version: 2.7.8
23
+
24
+ - name: Test the Gem
25
+ run: |
26
+ bundle
27
+ bundle exec rake
28
+
29
+ # - name: Publish to GPR
30
+ # run: |
31
+ # mkdir -p $HOME/.gem
32
+ # touch $HOME/.gem/credentials
33
+ # chmod 0600 $HOME/.gem/credentials
34
+ # printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
35
+ # gem build *.gemspec
36
+ # gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
37
+ # env:
38
+ # GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
39
+ # OWNER: ${{ github.repository_owner }}
40
+
41
+ - name: Publish to RubyGems
42
+ run: |
43
+ mkdir -p $HOME/.gem
44
+ touch $HOME/.gem/credentials
45
+ chmod 0600 $HOME/.gem/credentials
46
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
47
+ gem build *.gemspec
48
+ gem push *.gem
49
+ env:
50
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,14 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2024-02-07 13:48:55 UTC using RuboCop version 1.60.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: Severity, Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'aston.gemspec'
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.6
6
+ before_install: gem install bundler -v 2.1.4
@@ -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 aleksei.matiushkin@kantox.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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in aston.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ aston (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ amazing_print (1.5.0)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.5.0)
12
+ method_source (1.0.0)
13
+ prop_check (0.18.1)
14
+ amazing_print (~> 1.2)
15
+ pry (0.14.2)
16
+ coderay (~> 1.1)
17
+ method_source (~> 1.0)
18
+ rake (12.3.3)
19
+ rspec (3.12.0)
20
+ rspec-core (~> 3.12.0)
21
+ rspec-expectations (~> 3.12.0)
22
+ rspec-mocks (~> 3.12.0)
23
+ rspec-core (3.12.1)
24
+ rspec-support (~> 3.12.0)
25
+ rspec-expectations (3.12.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.12.0)
28
+ rspec-mocks (3.12.3)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.12.0)
31
+ rspec-support (3.12.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ aston!
38
+ prop_check
39
+ pry
40
+ rake (~> 12.0)
41
+ rspec (~> 3.0)
42
+
43
+ BUNDLED WITH
44
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Aleksei Matiushkin
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,44 @@
1
+ # Aston
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/aston`. 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 'aston'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install aston
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. Then, run `rake spec` to run the tests. 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/am-kantox/aston. 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/am-kantox/aston/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Aston project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/am-kantox/aston/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
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
+ task default: :spec
data/aston.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/aston/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'aston'
7
+ spec.version = Aston::VERSION
8
+ spec.authors = ['Aleksei Matiushkin']
9
+ spec.email = ['aleksei.matiushkin@kantox.com']
10
+
11
+ spec.summary = 'Helper to produce JSON hashes representing XML'
12
+ spec.description = 'Hash/JSON is not isomorphic to XML, unless produced with this library'
13
+ spec.homepage = 'https://github.com/am-kantox/aston'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/am-kantox/aston'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/am-kantox/aston/CHANGELOG.md'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_development_dependency 'prop_check'
33
+ spec.add_development_dependency 'pry'
34
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Aston
4
+ VERSION = '0.1.0'
5
+ end
data/lib/aston.rb ADDED
@@ -0,0 +1,168 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aston/version'
4
+
5
+ # Aston class keeps, modifies, and produces JSON which is isomorphic to XML
6
+ class Aston
7
+ class Error < StandardError; end
8
+
9
+ # Wrapper for attributes
10
+ class Attributes
11
+ attr_reader :data
12
+
13
+ def initialize(data)
14
+ @data = data
15
+ end
16
+
17
+ def [](key)
18
+ @data[key]
19
+ end
20
+
21
+ def []=(key, value)
22
+ @data[key] = value
23
+ end
24
+
25
+ def to_s
26
+ @data.map { |k, v| "#{k}='#{v}'" }.join(' ')
27
+ end
28
+
29
+ def ==(other)
30
+ other.is_a?(Attributes) && @data == other.data
31
+ end
32
+
33
+ def size
34
+ @data.size
35
+ end
36
+ end
37
+
38
+ # Wrapper for content
39
+ class Content
40
+ attr_reader :data
41
+
42
+ def initialize(data)
43
+ @data = data
44
+ end
45
+
46
+ def <<(elem)
47
+ @data << elem
48
+ end
49
+
50
+ def [](index)
51
+ @data[index]
52
+ rescue StandardError => e
53
+ raise Error, e
54
+ end
55
+
56
+ def ==(other)
57
+ other.is_a?(Content) && @data == other.data
58
+ end
59
+
60
+ def size
61
+ @data.size
62
+ end
63
+
64
+ def to_s
65
+ @data.map(&:to_s).join("\n")
66
+ end
67
+ end
68
+
69
+ attr_reader :name, :attributes, :content
70
+
71
+ def initialize(name, attributes: {}, content: [])
72
+ @name = name
73
+ @attributes = Attributes.new(attributes)
74
+ @content = Content.new(content)
75
+ end
76
+
77
+ def [](key)
78
+ @attributes[key]
79
+ end
80
+
81
+ def []=(key, value)
82
+ @attributes[key] = value
83
+ end
84
+
85
+ def <<(value)
86
+ @content << value
87
+ end
88
+
89
+ def ==(other)
90
+ other.is_a?(Aston) && @name == other.name && @attributes == other.attributes && @content == other.content
91
+ end
92
+
93
+ def to_s
94
+ comment = "<!-- Aston:#{__id__}:#{name} -->"
95
+ opening = @attributes.data.empty? ? "<#{name}>" : ['<', name, *@attributes].join(' ') << '>'
96
+ [comment, opening, *@content, "</#{name}>"].join("\n")
97
+ end
98
+
99
+ def paths
100
+ do_paths([], [])
101
+ end
102
+
103
+ def find(name)
104
+ @content.data.find { |a| a.is_a?(Aston) && a.name == name }
105
+ end
106
+
107
+ def update_in(path, create_intermediate: true, &_block)
108
+ yield clamber(path, create_intermediate)
109
+ rescue StandardError => e
110
+ raise Error, e
111
+ end
112
+
113
+ def put_attribute(path, name, value, create_intermediate: true)
114
+ tap { clamber(path, create_intermediate)[name] = value }
115
+ rescue StandardError => e
116
+ raise Error, e
117
+ end
118
+
119
+ def put_content(path, aston, create_intermediate: true)
120
+ tap { clamber(path, create_intermediate) << aston }
121
+ rescue StandardError => e
122
+ raise Error, e
123
+ end
124
+
125
+ def get(path, default: nil)
126
+ path = fix_path(path)
127
+ path.reduce(self) do |memo, e|
128
+ current = memo.find(e)
129
+
130
+ case current
131
+ when NilClass then break default
132
+ when String then current
133
+ when Aston then current
134
+ end
135
+ end
136
+ end
137
+
138
+ protected
139
+
140
+ def do_paths(path, acc)
141
+ content = @content.data.select { |c| c.is_a?(Aston) }
142
+ return [path + [name]] if content.empty?
143
+
144
+ content.map do |e|
145
+ e.do_paths(path + [name], acc)
146
+ end.flatten(1)
147
+ end
148
+
149
+ private
150
+
151
+ def clamber(path, create_intermediate)
152
+ fix_path(path).reduce(self) do |memo, e|
153
+ current = memo.find(e)
154
+
155
+ case current
156
+ when NilClass then create_intermediate ? Aston.new(e).tap { |aston| memo << aston } : break
157
+ when Aston then current
158
+ end
159
+ end
160
+ end
161
+
162
+ def fix_path(path)
163
+ path = path.split('.') if path.is_a?(String)
164
+ raise Error, 'Path must be an array' unless path.is_a?(Array)
165
+
166
+ path
167
+ end
168
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aston
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aleksei Matiushkin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prop_check
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Hash/JSON is not isomorphic to XML, unless produced with this library
42
+ email:
43
+ - aleksei.matiushkin@kantox.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/workflows/gem-push.yml"
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".rubocop.yml"
52
+ - ".rubocop_todo.yml"
53
+ - ".travis.yml"
54
+ - CODE_OF_CONDUCT.md
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - aston.gemspec
61
+ - lib/aston.rb
62
+ - lib/aston/version.rb
63
+ homepage: https://github.com/am-kantox/aston
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ allowed_push_host: https://rubygems.org
68
+ homepage_uri: https://github.com/am-kantox/aston
69
+ source_code_uri: https://github.com/am-kantox/aston
70
+ changelog_uri: https://github.com/am-kantox/aston/CHANGELOG.md
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.3.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.1.6
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Helper to produce JSON hashes representing XML
90
+ test_files: []