lib/builder.rb in sinatra_resource-0.3.2 vs lib/builder.rb in sinatra_resource-0.3.3
- old
+ new
@@ -3,15 +3,15 @@
class Builder
def initialize(klass)
@klass = klass
- @resource_config = @klass.resource_config
- @child_association = @resource_config[:child_association]
- @model = @resource_config[:model]
- @parent = @resource_config[:parent]
- @path = @resource_config[:path]
+ @resource_config = @klass.resource_config
+ @child_assoc = @resource_config[:child_assoc]
+ @model = @resource_config[:model]
+ @parent = @resource_config[:parent]
+ @path = @resource_config[:path]
if @parent
@parent_resource_config = @parent.resource_config
@parent_model = @parent_resource_config[:model]
end
end
@@ -29,143 +29,143 @@
model = @model
resource_config = @resource_config
if !@parent
@klass.get '/:id/?' do
id = params.delete("id")
- role = get_role(model, id)
+ role = role_for(model, id)
document = document_for_get_one(role, model, resource_config, true, id, nil, nil)
resource = build_resource(role, document, resource_config)
display(:read, resource, resource_config)
end
else
- association = @child_association
+ child_assoc = @child_assoc
parent_model = @parent_model
parent_resource_config = @parent_resource_config
path = @path
@parent.get "/:parent_id/#{path}/:id/?" do
id = params.delete("id")
parent_id = params.delete("parent_id")
- parent_role = get_role(parent_model, parent_id)
+ parent_role = role_for(parent_model, parent_id)
parent_document = document_for_get_one(parent_role, parent_model, parent_resource_config, false, parent_id, nil, nil)
# ------
- role = get_role(model, id)
- document = document_for_get_one(role, model, resource_config, true, id, parent_document, association)
+ role = role_for_nested(parent_document, child_assoc, model, id)
+ document = document_for_get_one(role, model, resource_config, true, id, parent_document, child_assoc)
resource = build_resource(role, document, resource_config)
- display(:read, resource, resource_config)
+ display(:read, resource, resource_config, parent_id)
end
end
end
def build_get_many
model = @model
resource_config = @resource_config
if !@parent
@klass.get '/?' do
- role = get_role(model)
+ role = lookup_role(nil)
documents = documents_for_get_many(role, model, resource_config, true, nil, nil)
resources = build_resources(documents, resource_config)
display(:list, resources, resource_config)
end
else
- association = @child_association
+ child_assoc = @child_assoc
parent_model = @parent_model
parent_resource_config = @parent_resource_config
path = @path
@parent.get "/:parent_id/#{path}/?" do
parent_id = params.delete("parent_id")
- parent_role = get_role(parent_model, parent_id)
+ parent_role = role_for(parent_model, parent_id)
parent_document = document_for_get_one(parent_role, parent_model, parent_resource_config, false, parent_id, nil, nil)
# ------
- role = get_role(model)
- documents = documents_for_get_many(role, model, resource_config, true, parent_document, association)
+ role = lookup_role(nil)
+ documents = documents_for_get_many(role, model, resource_config, true, parent_document, child_assoc)
resources = build_resources(documents, resource_config)
- display(:list, resources, resource_config)
+ display(:list, resources, resource_config, parent_id)
end
end
end
def build_post
model = @model
resource_config = @resource_config
if !@parent
@klass.post '/?' do
- role = get_role(model)
+ role = lookup_role(nil)
document = document_for_post(role, model, resource_config, true, nil, nil)
resource = build_resource(role, document, resource_config)
display(:create, resource, resource_config)
end
else
- association = @child_association
+ child_assoc = @child_assoc
parent_model = @parent_model
parent_resource_config = @parent_resource_config
path = @path
@parent.post "/:parent_id/#{path}/?" do
parent_id = params.delete("parent_id")
- parent_role = get_role(parent_model, parent_id)
+ parent_role = role_for(parent_model, parent_id)
parent_document = document_for_get_one(parent_role, parent_model, parent_resource_config, false, parent_id, nil, nil)
# ------
- role = get_role(model)
- document = document_for_post(role, model, resource_config, true, parent_document, association)
+ role = lookup_role(nil)
+ document = document_for_post(role, model, resource_config, true, parent_document, child_assoc)
resource = build_resource(role, document, resource_config)
- display(:create, resource, resource_config)
+ display(:create, resource, resource_config, parent_id)
end
end
end
def build_put
model = @model
resource_config = @resource_config
if !@parent
@klass.put '/:id/?' do
id = params.delete("id")
- role = get_role(model, id)
+ role = role_for(model, id)
document = document_for_put(role, model, resource_config, true, id, nil, nil)
resource = build_resource(role, document, resource_config)
display(:update, resource, resource_config)
end
else
- association = @child_association
+ child_assoc = @child_assoc
parent_model = @parent_model
parent_resource_config = @parent_resource_config
path = @path
@parent.put "/:parent_id/#{path}/:id/?" do
id = params.delete("id")
parent_id = params.delete("parent_id")
- parent_role = get_role(parent_model, parent_id)
+ parent_role = role_for(parent_model, parent_id)
parent_document = document_for_get_one(parent_role, parent_model, parent_resource_config, false, parent_id, id, id)
# ------
- role = get_role(model, id)
- document = document_for_put(role, model, resource_config, true, id, parent_document, association)
+ role = role_for_nested(parent_document, child_assoc, model, id)
+ document = document_for_put(role, model, resource_config, true, id, parent_document, child_assoc)
resource = build_resource(role, document, resource_config)
- display(:update, resource, resource_config)
+ display(:update, resource, resource_config, parent_id)
end
end
end
def build_delete
model = @model
resource_config = @resource_config
if !@parent
@klass.delete '/:id/?' do
id = params.delete("id")
- role = get_role(model, id)
+ role = role_for(model, id)
document_for_delete(role, model, resource_config, true, id, nil, nil)
display(:delete, "", resource_config)
end
else
- association = @child_association
+ child_assoc = @child_assoc
parent_model = @parent_model
parent_resource_config = @parent_resource_config
path = @path
@parent.delete "/:parent_id/#{path}/:id/?" do
id = params.delete("id")
parent_id = params.delete("parent_id")
- parent_role = get_role(parent_model, parent_id)
+ parent_role = role_for(parent_model, parent_id)
parent_document = document_for_get_one(parent_role, parent_model, parent_resource_config, false, parent_id, nil, nil)
# ------
- role = get_role(model, id)
- document_for_delete(role, model, resource_config, true, id, parent_document, association)
- display(:delete, "", resource_config)
+ role = role_for_nested(parent_document, child_assoc, model, id)
+ document_for_delete(role, model, resource_config, true, id, parent_document, child_assoc)
+ display(:delete, "", resource_config, parent_id)
end
end
end
def build_helpers