Sire
Simple Immutable Relational Entity
Defining
require 'sire'
Order = Sire.entity(:line_items, :total)
LineItem = Sire.entity(:purchasable, :quantity)
LineItems = Sire.aggregate(LineItem)
Product = Sire.entity(:name, :price)
Service = Sire.entity(:name, :rate)
Purchasable = Sire.relation(Product, Service)
Rate = Sire.entity(:price, :period)
Initializing
rate = Rate[price: 13.99, period: :weekly]
service1 = Service[name: 'Consulting', rate: rate]
service2 = Service[name: 'Support', rate: { price: 56.50, period: :monthly }]
line_item = LineItem[purchasable: { name: 'Hat', price: 5.36 }, quantity: 2]
order = Order[line_items: [line_item, {purchasable: service1, quantity: 1}], total: 12.50]
Usage
rate.price
rate.attributes
rate2 = rate.merge(price: 10.00)
rate == rate2
rate.map { |k, v| "#{k} = #{v}" }.join(', ')
Installation
Add this line to your application's Gemfile:
gem 'sire'
Contributing
- Fork it ( https://github.com/[my-github-username]/sire/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request