New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

aston

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aston

  • 0.2.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Aston

The tiny library providing a tooling to deal with ASTON, which is like JSON, but isomorphic to XML.

Installation

Add this line to your application's Gemfile:

gem 'aston'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install aston

Usage

Aston.new(:root).
    then { |a| a.put_attribute([:bar, :baz], 'attr', 'value') }.
    then { |a| a.put_content([:bar, :baz], 'Hello, world!') }
#⇒ #<Aston:0x0000646926a11370
#  @attributes=#<Aston::Attributes:0x0000646926a112f8 @data={}>,
#  @content=
#   #<Aston::Content:0x0000646926a112d0
#    @data=
#     [#<Aston:0x0000646926a110f0
#       @attributes=#<Aston::Attributes:0x0000646926a11078 @data={}>,
#       @content=
#        #<Aston::Content:0x0000646926a11050
#         @data=
#          [#<Aston:0x0000646926a10f38
#            @attributes=#<Aston::Attributes:0x0000646926a10ec0 @data={"attr"=>"value"}>,
#            @content=#<Aston::Content:0x0000646926a10e98 @data=["Hello, world!"]>,
#            @name=:baz>]>,
#       @name=:bar>]>,
#  @name=:root>

#to_s

puts Aston.new(:root).
        then { |a| a.put_attribute([:bar, :baz], 'attr', 'value') }.
        then { |a| a.put_content([:bar, :baz], "Hello, world!") }.
        to_s
<!-- Aston:1380:root -->
<root>
    <!-- Aston:1400:bar -->
    <bar>
        <!-- Aston:1420:baz -->
        <baz attr='value'>
            Hello, world!
        </baz>
    </bar>
</root>

#to_json

puts Aston.new(:root).
        then { |a| a.put_attribute([:bar, :baz], 'attr', 'value') }.
        then { |a| a.put_content([:bar, :baz], "Hello, world!") }.
        to_json
#⇒ {"name":"root","attributes":{},"content":[
#     {"name":"bar","attributes":{},"content":[
#        {"name":"baz","attributes":{"attr":"value"},"content":["Hello, world!"]}]}]}

Aston#parse_hash

json = Aston.new(:root).
         then { |a| a.put_attribute([:bar, :baz], 'attr', 'value') }.
         then { |a| a.put_content([:bar, :baz], "Hello, world!") }.
         to_json
Aston.parse_hash(JSON.parse(json))
#⇒ #<Aston:0x0000643279caa890
#  @attributes=#<Aston::Attributes:0x0000643279caa868 @data={}>,
#  @content=
#   #<Aston::Content:0x0000643279caa840
#    @data=
#     [#<Aston:0x0000643279caa930
#       @attributes=#<Aston::Attributes:0x0000643279caa908 @data={}>,
#       @content=
#        #<Aston::Content:0x0000643279caa8e0
#         @data=
#          [#<Aston:0x0000643279caa9d0
#            @attributes=#<Aston::Attributes:0x0000643279caa9a8 @data={"attr"=>"value"}>,
#            @content=#<Aston::Content:0x0000643279caa980 @data=["Hello, world!"]>,
#            @name="baz">]>,
#       @name="bar">]>,
#  @name="root">

#update_in

a = Aston.new :aston, attributes: { foo: :bar }
a.put_attribute %i[bar baz], :ok, 42
a.put_content %i[bar baz], 'Hello'
a.update_in %i[bar baz] do |content|
  content <<
    Aston.new(:seq, attributes: { name: :seq1 }) <<
    Aston.new(:seq, attributes: { name: :seq2 }) <<
    Aston.new(:seq, attributes: { name: :seq3 })
end

#⇒ [#<Aston:0x0000643279c616e0
#   @attributes=#<Aston::Attributes:0x0000643279c61668 @data={:ok=>42}>,
#   @content=
#    #<Aston::Content:0x0000643279c61640
#     @data=
#      ["Hello",
#       #<Aston:0x0000643279c60d58
#        @attributes=#<Aston::Attributes:0x0000643279c60d08 @data={:name=>:seq1}>,
#        @content=#<Aston::Content:0x0000643279c60ce0 @data=[]>,
#        @name=:seq>,
#       #<Aston:0x0000643279c60c68
#        @attributes=#<Aston::Attributes:0x0000643279c60c18 @data={:name=>:seq2}>,
#        @content=#<Aston::Content:0x0000643279c60bc8 @data=[]>,
#        @name=:seq>,
#       #<Aston:0x0000643279c60b50
#        @attributes=#<Aston::Attributes:0x0000643279c60b00 @data={:name=>:seq3}>,
#        @content=#<Aston::Content:0x0000643279c60ad8 @data=[]>,
#        @name=:seq>]>,
#   @name=:baz>]

#update_in returns an array of updated elements on the path given. Unlike #update_in.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Aston project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

FAQs

Package last updated on 19 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc