Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Ambry is a database and ORM replacement for small, mostly static models. Use it to replace database-persisted seed data and ad-hoc structures in your app or library with plain old Ruby objects that are searchable via a fast, simple database-like API.
It implements Active Model and has generators to integrate nicely with Rails. You can store your data in either YAML or dump file.
For more info, take a peek at the docs, or read on for some quick samples.
# Create a model.
class Country
# Turn any Ruby object into a Ambry model by extending this module.
extend Ambry::Model
# The first field listed here will be the "primary key."
field :tld, :name
# Chainable filters, sort of like Active Record scopes.
filters do
def big
find {|c| c.population > 100_000_000 }
end
def in_region(region)
find {|c| c.region == region }
end
def alphabetical
sort_by {|c| c.name }
end
end
# Root filter, can be used to setup relations.
def regions
Region.find {|r| r.id == region }
end
end
# create some contries
Country.create :tld => "AR", :name => "Argentina", :region => :america, :population => 40_000_000
Country.create :tld => "CA", :name => "Canada", :region => :america, :population => 34_000_000
Country.create :tld => "JP", :name => "Japan", :region => :asia, :population => 127_000_000
Country.create :tld => "CN", :name => "China", :region => :asia, :population => 1_300_000_000
# etc.
# Do some searches
big_asian_countries = Country.big.in_region(:asia)
countries_that_start_with_c = Country.find {|c| c.name =~ /^C/ }
# #first and #last only make sense if you run Ruby 1.9 (creation order) or explicitly specified an order
first_alphabetical = Country.alphabetical.first
last_alphabetical = Country.alphabetical.last
Ambry can be useful for refactoring code with large hash constants and long case statements. Sometimes it's hard to figure out where code ends and data begins, but if your code looks like it could be simplified significantly by putting some things in a data store, yet it's not enough data to justify something like SQLite, then Ambry could be a good fit.
gem install ambry
Ambry has been tested against these current Rubies, and is likely compatible with others.
Many thanks to Adrián Mugnolo for initial code review and feedback.
Copyright (c) 2011 Norman Clarke
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Unknown package
We found that ambry 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.