#49 new
ronin-14694 (at lighthouseapp)

Explicit slot declaration

Reported by ronin-14694 (at lighthouseapp) | May 3rd, 2008 @ 07:14 PM

I'd like to propose a way to declare available slots explicitly, similar to DataMapper's syntax: http://datamapper.org/docs/prope... . If you go one step further, (custom) typing of properties could also be interesting to have.

On top of that you could 'freeze' the Meta definition, to disallow adding any arbitrary slots. Which makes sense when accepting data using 'params' of your favorite web framework. Off coarse this goes against some of the principles of StrokeDB, but it would be useful nonetheless. Methods like attr_protected or attr_accessible could provide an implementation for this.

Comments and changes to this ticket

  • Yurii Rashkovskii

    Yurii Rashkovskii May 3rd, 2008 @ 07:14 PM

    • Assigned user set to “Yurii Rashkovskii”
  • Sean Ouimet

    Sean Ouimet June 18th, 2008 @ 11:36 AM

    Explicit slot declaration is similar to validates_type_of + validates_presence_of, except default values are not accounted for.

    Some shortcut commands could make it easier to assign defaults or limit access when needed.

    Member = StrokeDB::Meta.new do 
       #allow only these slots
       #presumably existing slot types could still be used
       available_slots 'name', 'email', 'age'
    
       #assign default values if not defined
       #if no default value listed with key, nil is assumed
       #(so :age would be :age=>nil)
       default_slots :age, :status=>"newbie"
       
       #Allow no more slot types to be added (works well with above defaults setting nil first -- or could be based on all docs using the Meta).
       #My issues with this is it would make adding a new slot type (intentionally) more difficult (impossible?), whereas available_slots could be added to.
       freeze_slots
    end
    
  • Justin Reagor

    Justin Reagor July 10th, 2008 @ 09:07 AM

    • Tag set to @idea, meta

    This would look even better if it resembled DataMapper's DataMapper::Resource::ClassMethods "property" method... something like this:

    Member = StrokeDB::Meta.new do

    slot :name # no default for variable storage

    slot :age, :default => 'newbie'

    slots.freeze!

    end

    There's no reason for StrokeDB to state primitives upon initialization is there? Since pretty much any value should be able to be stored in any slot?

    Just a quick question and suggestion... ;)

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

StrokeDB is an embeddable distributed document database written in Ruby

Shared Ticket Bins

Tags