Giter Club home page Giter Club logo

hyperactiveresource's Introduction

HyperactiveResource

HyperActiveResource extends ActiveResource so it works properly and behaves more like ActiveRecord

Many have said that ActiveResource is not really "complete". On the surface, this means that some features that are documented aren't implemented. Digging a little deeper, we find that some features that should exist don't.

Arguably, a "complete" ActiveResource would behave like ActiveRecord or, as the rdoc for ActiveResource states "very similarly to Active Record".

Hyperactive Resource is MDL's extension to ActiveResource::Base written to support our Patient Registry and goes a long way towards the goal of an ActiveResource that behaves like ActiveRecord.

Features

  • Client side validations
  • Hooks for before_validate, before_save
  • Dynamic finders: find_by_X
  • save!
  • Awareness of associations between resources: belongs_to, has_many, has_one & columns
    • Patient.new.name returns nil instead of MethodMissing
    • Patient.new.races returns [] instead of MethodMissing
    • pat = Patient.new; pat.gender_id = 1; pat.gender #Will return find the gender obj
  • Resources can be associated with records
  • Records can be associated with records
  • ActiveRecord-like attributes= (updates rather than replaces)
  • ActiveRecord-like #load that doesn't #dup attributes (stores direct reference)
  • Supports saving resources that :include other resources via:
    • Nested resource saving (creating a patient will create their associated addresses)
    • Mapping associations ([:gender].id will serialize as :gender_id)

Example

  1. Create a HyperactiveResource where you would normally use ActiveResource and define the meta-data/associations that drive the dynamic magic:
class Address < HyperactiveResource
  self.columns = [ :street_address, :city, :zipcode, :home_phone_number ]
  self.belong_tos = [ :country, :state ]
  self.has_manys = [ :people ]
end
  1. Enjoy the magic
address = Address.new
address.country # nil instead of method_missing
address.country_id = 5
address.country #Returns Country.find(5)

etc..

Copyright (c) 2008 Medical Decision Logic, 2013 Massimo Maino released under the MIT license

hyperactiveresource's People

Contributors

lukegalea avatar maintux avatar

Watchers

 avatar  avatar  avatar

Forkers

kamur

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.