Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spira-active_record_isomorphisms

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spira-active_record_isomorphisms

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

spira-active_record_isomorphisms Build Status Gem Version

Establish isomorphisms between your Spira and ActiveRecord models.

Installation

Add this line to your application's Gemfile:

gem 'spira-active_record_isomorphisms'

And then execute:

$ bundle

Or install it yourself as:

$ gem install spira-active_record_isomorphisms

Usage

Defining Isomorphisms

Isomorphisms are established by adding an isomorphic_with call to your Spira model declaration. For example, given an ActiveRecord User model:

class User < ActiveRecord::Base; end

with id, email and encrypted_password properties, an isomorphic Spira Person model can be defined:

class Person < Spira::Base
  configure base_uri: 'http://example.org/example/people',
            default_vocabulary: 'http://example.org/example/vocab'

  isomorphic_with :user
  property :name, predicate: FOAF.name, type: String
end

Associating Models

Models can be associated by setting the corresponding attributes:

> bob = Person.for('bob')
=> <Person:2202810640 @subject: http://example.org/example/people/bob>
> bob.user = User.find(1)
=> #<User id: 1, email: "bob@example.com", ...>
> bob.user
=> #<User id: 1, email: "bob@example.com", ...>
> bob.save
=> <Person:2202810640 @subject: http://example.org/example/people/bob>
> User.find(1).person
=> <Person:2202810640 @subject: http://example.org/example/people/bob>
> bob.user_id
=> 1

Note that:

  • A default_vocabulary must be set on the Spira model.
  • The Spira model must be saved before the reverse association can be accessed.
  • The two classes must have different names.
  • An id property is added to the Spira model corresponding to the name of the ActiveRecord model (in this case user_id).

Delegated Attributes

By default, attributes are delegated in both directions:

> bob = Person.for('bob')
=> <Person:2202810640 @subject: http://example.org/example/people/bob>
> bob.user = User.find(1)
=> #<User id: 1, email: "bob@example.com", ...>
> bob.email
=> "bob@example.com"
> bob.name = 'Bob'
=> "Bob"
> User.find(1).name
=> "Bob"

This can be disabled by setting delegation to false: isomorphic_with :user, delegation: false

Contributing

  1. Fork it ( https://github.com/nhurden/spira-active\_record\_isomorphisms/fork )
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create a new Pull Request

FAQs

Package last updated on 30 Dec 2014

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