Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mauricioszabo/clojuby
Ruby on Clojure
https://github.com/mauricioszabo/clojuby
clojure conversion ruby
Last synced: about 2 months ago
JSON representation
Ruby on Clojure
- Host: GitHub
- URL: https://github.com/mauricioszabo/clojuby
- Owner: mauricioszabo
- License: epl-1.0
- Created: 2017-05-08T02:12:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-10-07T17:12:42.000Z (about 3 years ago)
- Last Synced: 2023-03-10T20:22:45.893Z (almost 2 years ago)
- Topics: clojure, conversion, ruby
- Language: Clojure
- Size: 53.7 KB
- Stars: 7
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Clojuby
Because you can rubyfy Clojure, but cannot clojurify Ruby...
... or whatever that means
## Usage
Let's say we have ActiveRecord and Sinatra gems installed:
```clojure
(ns sinatra-ar (:require [clojuby.core :refer [rb rb-require ruby] :as rb]))(rb-require "activerecord-jdbcsqlite3-adapter")
(rb-require "sinatra")
(ruby
(doto (rb ActiveRecord.Base)
(.establish-connection {:adapter :sqlite3
:database ":memory:"}))(doto (defclass User (rb ActiveRecord.Base)
(defn self.greater [age] (.where self "users.age > ?" age)))
(.validates-presence-of :name))(defclass CreateUsers (rb ActiveRecord.Migration)
(defn change []
(.create-table self :users (fn [t]
(doto t
(.string :name)
(.integer :age)
(.string :likes)
(.timestamps))))
(doto User
(.create! {:name "Foo" :age 42 :likes "Ruby"})
(.create! {:name "Bar" :age 22 :likes "Clojure"})
(.create! {:name "Baz" :age 20 :likes "Java"}))))
(.migrate CreateUsers :up))(ruby
(doto (defclass App (rb Sinatra.Base))
(.get "/" (fn []
(.erb self "<% User.all.each do |user| %>
<%= user.name %>
<%= user.age %>
Edit
<% end %>")))
;; AND SO ON...
(.run!)))```
A full example is on `examples/sinatra_ar.clj`.
## License
Copyright © 2017 Maurício Szabo
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.