Sha256: 273e55632c023ab98aa2ea7f8c7f8135a59e85abbed3654fdd3dc4f3090c34a8

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

class Recipe < Spyke::Base
  has_many :groups
  has_one :image
  has_one :background_image, class_name: 'Image', uri: nil
  has_one :alternate, class_name: 'Recipe', uri: '/recipes/:recipe_id/alternates/recipe'
  belongs_to :user

  scope :published, -> { where(status: 'published') }
  attributes :title

  before_save :before_save_callback
  before_create :before_create_callback
  before_update :before_update_callback

  accepts_nested_attributes_for :image, :user, :groups

  def self.page(number)
    if number.present?
      where(page: number)
    else
      all
    end
  end

  def ingredients
    groups.first.ingredients
  end

  private

    def before_create_callback; end
    def before_update_callback; end
    def before_save_callback; end
end

class Image < Spyke::Base
  method_for :create, :put
end

class StepImage < Image
end

class RecipeImage < Image
  uri '/recipes/:recipe_id/image'
  validates :url, presence: true
  attributes :url
  include_root_in_json false
end

class Group < Spyke::Base
  has_many :ingredients, uri: nil
  accepts_nested_attributes_for :ingredients
end

class Ingredient < Spyke::Base
  uri '/recipes/:recipe_id/ingredients/:id'
end

class User < Spyke::Base
  has_many :recipes
end

class Photo < Spyke::Base
  uri '/images/photos/:id'
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spyke-1.2.0 test/support/fixtures.rb
spyke-1.1.2 test/support/fixtures.rb
spyke-1.1.1 test/support/fixtures.rb
spyke-1.1.0 test/support/fixtures.rb
spyke-1.0.2 test/support/fixtures.rb
spyke-1.0.1 test/support/fixtures.rb
spyke-1.0.0 test/support/fixtures.rb