Sha256: f53150e7413983aa1e21c95f5c3944b6c56846b1ede21660a2dbb766104108c7
Contents?: true
Size: 1.67 KB
Versions: 3
Compression:
Stored size: 1.67 KB
Contents
#!/usr/bin/env ruby require "bundler/setup" require "re_sorcery" require "pry" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. class Horse include ReSorcery attr_reader :name, :age, :children def initialize(name, age, children) @name = name @age = age @children = children end field :name, String field :age, Numeric field :children, array(Horse) links do link 'self', "/horses/#{name}" end end class HorseCollection include ReSorcery attr_reader :person, :horses def initialize(person, horses) @person = person @horses = horses end field :horses, array(Horse) links do link 'self', "/person/#{person.name}/horses" if person.kind == 'owner' end end class Person include ReSorcery attr_reader :name, :age, :kind, :horses def initialize(name, age, kind, horses) @name = name @age = age @kind = kind @horses = horses end field :name, String field :age, Numeric field :kind, is("owner", "jockey") field :horses, HorseCollection, -> { HorseCollection.new(self, horses) } links do link 'self', "/users/#{name}" end end def dave Horse.new("Dave", 1, []) end def rigby Horse.new("Rigby", 2, []) end def ruby Horse.new("Ruby", 6, [dave, rigby]) end def bad_horse Horse.new("bad horse", 4, [bob]) end def bob Person.new("Bob", 70, "owner", [dave, rigby, ruby]) end def jockey Person.new("Jack", 23, "jockey", [dave, ruby]) end def bab Person.new("Bab", "bad", "owner", [dave, rigby, ruby]) end def bab2 Person.new("Bob", 70, "owner", [dave, rigby, bad_horse]) end Pry.start
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
re_sorcery-0.3.0 | bin/console |
re_sorcery-0.2.0 | bin/console |
re_sorcery-0.1.0 | bin/console |