README.md in static_association-0.0.2 vs README.md in static_association-0.1.0
- old
+ new
@@ -1,16 +1,18 @@
# StaticAssociation
-Adds basic ActiveRecord like associations to static data.
+[![Build Status](https://travis-ci.org/New-Bamboo/static_association.png?branch=master)](https://travis-ci.org/New-Bamboo/static_association)
-This has been extracted from ProjectsDB and Hotleads, see the `BudgetCategory`, `Project` and `ArchiveReason`, `Lead` classes respectively for examples.
+Adds basic ActiveRecord-like associations to static data.
## Installation
Add this line to your application's Gemfile:
- gem 'static_association'
+```ruby
+gem 'static_association'
+```
And then execute:
$ bundle
@@ -22,28 +24,36 @@
### Static Models
Create your static association class:
- class Days
- include StaticAssociation
+```ruby
+class Day
+ include StaticAssociation
- attr_accessor :name
+ attr_accessor :name
- record id: 0 do |day|
- day.name = :monday
- end
- end
+ record id: 0 do |day|
+ day.name = :monday
+ end
+end
+```
Calling `record` will allow you to create an instance of this static model, a unique id is mandatory. The newly created object is yielded to the passed block.
-The `Days` class will gain an `all` and `find` method.
+The `Day` class will gain an `all` and `find` method.
### Associations
Currently just a 'belongs to' association can be created. This behaviour can be mixed into an `ActiveRecord` model:
- belongs_to_static :day
+```ruby
+class Event < ActiveRecord::Base
+ extend StaticAssociation::AssociationHelpers
+
+ belongs_to_static :day
+end
+```
This assumes your model has a field `day_id`.
## Contributing