
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Convert an heterogeneous tree structure in nested ActiveModel::Model
objects.
For instance, if you have a JSON object describing a train journey:
{
"id": 987,
"connections": [
{
"start": "London",
"finish": "Paris",
"departure_time": "2015-07-11T09:23:00+01:00",
"arrival_time": "2015-07-11T12:41:00+02:00",
"fare": {
"currency": "GBP",
"value": 159.0
}
},
{
"start": "Paris",
"finish": "Barcelona",
"departure_time": "2015-07-11T13:56:00+02:00",
"arrival_time": "2015-07-11T20:17:00+02:00",
"fare": {
"currency": "GBP",
"value": 50.0
}
}
]
}
You can define a Ruby class describing it as
class TravelOption
include Data2ruby
has_one :journey do
attr_accessor :id
validates_numericality_of :id, only_integer: true
has_many :connections do
attr_accessor :start, :finish, :departure_time, :arrival_time
validates_presence_of :start, :finish, :departure_time, :arrival_time
has_one :fare do
attr_accessor :currency, :value
validates_presence_of :currency
validates_numericality_of :value
end
end
end
end
Then instantiate and validate:
travel_option = TravelOption.new(JSON.parse(json_string))
# run ActiveModel validations
travel_option.valid_structure? # => true
travel_option.invalid_items # => []
# navigate the associations
travel_option.journey.id # => 987
travel_option.connections[0].start # => "London"
travel_option.connections[0].fare.currency # => "GBP"
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.
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/rmaestroni/data2ruby.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that data2ruby demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.