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

whales

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

whales

  • 0.1.13
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

#Whales

There's Rails, there's Sails, so why not Whales? Whales is a lightweight web framework written in Ruby, inspired by popular MVC frameworks like Rails, Django, and Express.

##Installation

Whales can be installed using RubyGems: gem install 'whales'

Or you can include it directly in your projects Gemfile: gem 'whales', '0.1.1'

##Your First Whales Project Create a new app:

whales new MyApp

Start working:

# cd into the new folder
cd MyApp

# start the server
whales server

##Documentation## ###WhalesORM### WhalesORM is the object-relational mapper behind Whales. It connects to a SQLite database that the user can create and modify in their db/database.sql file.

####WhalesORM::Base#### The features of WhalesORM are accessed by making a class that inherits from WhalesORM::Base. The base class provides the following methods:

::all: returns all the instances of the class stored in the table.

::columns: returns an array with the columns of the class's table.

::destroy_all: deletes all the rows in the class's table.

::find(id): returns the object of the class with the given id.

::find_by_col_x(value): returns the object(s) of the class whose col_x equals value. Implemented using Ruby's method_missing. Also can be extended to ::find_by_col_x_and_col_y(val_x, val_y).

::table_name=(name): allows the user to set a custom table name for the class

::table_name: returns the table name, which defaults to the pluralized, camel-cased class name.

#attributes: returns the names of all the attributes for the object.

#attribute_values: returns the values for all the object's attributes.

#destroy: deletes the object from the database. Returns the object.

#insert: inserts the object as a row in the class's table

#save: if the object is not in the database, it inserts it; if it is, it calls update.

#update: updates the object's entry in the database

####WhalesORM::QueryMethods#### WhalesORM::Base gains additional methods by extending the WhalesORM::QueryMethods module.

::where(params): gets objects from the database that match the given params hash. This method is chainable and lazy-evaluating.

This is implemented using a WhalesORM::Relation class that inherits from Ruby's BasicObject. It puts off the database call until it gets a method call it doesn't recognize.

module WhalesORM
  class Relation < BasicObject
    ...
    def method_missing(method, *args, &blk)
      results = self.execute
      results.send(method, *args, &blk)
    end
    ...
  end
end

::includes(relation): helps to prevent N+1 queries by including the given relation in the query. Also lazy-evaluating.

####WhalesORM::Associatable#### WhalesORM::Base also extends WhalesORM::Associatable.

::belongs_to(relation_name): associates the class to relation_name via a foreign key relation_name_id so that the method #relation_name returns an object of class relation_name with id equal to relation__name_id

FAQs

Package last updated on 30 Dec 2015

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