couchbase / couchbase-ruby-model

The Active Model implementation for Couchbase Server built on couchbase-ruby-client
61 stars 23 forks source link

Add MassAssignmentSecurity #10

Closed jabberfest closed 11 years ago

jabberfest commented 11 years ago

Working on this now... should have a pull request by this weekend.

I wanted to get feedback if the following structure was ok for adding Mass Assignment support.

I figured unlike ActiveRecord we need to explicitly state what attributes exist in the model for Couchbase-Model.

If we then wanted to define what attributes are accessible or protected we would follow the expected convention from ActiveModel::MassAssignmentSecurity.

require 'couchbase/model'

class Post < Couchbase::Model
  attribute :title
  attribute :body
  attribute :draft

  attr_accessible :title, :as => admin
  attr_accessible :body, :as => user

end

And to Save if you needed to provide a role you could as part of the options hash

    p = Post.new(
                 :body  => 'filter',
                 :title => 'Hello world',
                 :draft => true)
    p.save(:as=> :admin)
avsej commented 11 years ago

looks totally OK to me

jabberfest commented 11 years ago

Duplicated the issue by accident. Closing.