Sha256: b2a9e9f163d097ea187aa2f1206f4f56d6284ccc63c59f991d42c5670270c5fd

Contents?: true

Size: 1.34 KB

Versions: 29

Compression:

Stored size: 1.34 KB

Contents

module DataCatalog

  class Categories < Base
    include Resource

    model Category

    # == Permissions

    roles Roles
    permission :list   => :basic
    permission :read   => :basic
    permission :create => :curator
    permission :update => :curator
    permission :delete => :curator

    # == Properties
    
    property :name
    property :log

    property :sources do |category|
      category.sources.map do |source|
        {
          "id"    => source.id,
          "href"  => "/sources/#{source.id}",
          "title" => source.title,
          "url"   => source.url,
        }
      end
    end
    
    # == Callbacks
    
    callback :before_create do |action|
      action.params["log"] = "before_create"
    end
    
    callback :after_create do |action, category|
      category.log += " after_create"
    end

    callback :before_update do |action, category|
      action.params["log"] = "before_update"
    end
    
    callback :after_update do |action, category|
      category.log += " after_update"
    end

    callback :before_destroy do |action, category|
      action.headers 'X-Test-Callbacks' => 'before_destroy'
    end
    
    callback :after_destroy do |action, category|
      x = action.response['X-Test-Callbacks']
      action.headers 'X-Test-Callbacks' => "#{x} after_destroy"
    end

  end
  
  Categories.build

end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
sinatra_resource-0.4.21 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.20 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.19 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.18 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.17 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.16 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.15 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.14 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.13 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.12 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.11 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.10 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.9 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.8 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.7 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.6 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.5 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.4 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.3 examples/datacatalog/resources/categories.rb
sinatra_resource-0.4.2 examples/datacatalog/resources/categories.rb