Skip to content

Permits and License generators

kristianmandrup edited this page Dec 24, 2010 · 1 revision

Permits Generator

Generates one or more permits in app/permits

Options

  • --orm : The ORM to use (active_record, data_mapper, mongoid, mongo_mapper) - creates a Rails initializer
  • --initializer : A Rails 3 initializer file for Permits is generated by default. Use --no-initializer option to disable this
  • --roles : The roles for which to generate permits ; default Guest (read all) and Admin (manage all)
  • --default-permits : By default :guest and :admin permits are generated. Use --no-default-permits option to disable this

$ rails g cancan:permits --orm active_record --roles guest author admin

What does the generator generate?

To get an understanding of what the generator generates for a Rails 3 application, try to run the spec permit_generator_spec.rb with RSpec 2 as follows:

In the file permits_generator_spec.rb make the following change config.remove_temp_dir = false This will prevent the rails /tmp dir from being deleted after the test run, so you can inspect what is generated in the Rails app.

Now run the generator spec to see the result: $ rspec spec/generators/cancan/permits_generator_spec.rb

Todo

The Permits generator should attempt to attempt to discover which roles are currently defined as available to the application, trying Cream#available_roles and then User#roles. The generator should then generate permits for those roles. Any roles specified in the --roles option should be merged with the roles available in the app.

Licenses Generator

Generates one or more licenses in app/licenses

Options

  • --licenses : The licenses to generate; default UserAdmin and Blogging licenses are generated
  • --default-licenses : By default exemplar licenses are generated. Use --no-default-licenses option to disable this

Run examples:

Generate default licenses:

$ rails g cancan:licenses

Genereate specific licenses (no defaults):

$ rails g cancan:licenses profile_administration article_editing --no-default-licenses

Create both specific and default licenses:

$ rails g cancan:licenses profile_administration article_editing

What does the generator generate?

To get an understanding of what the generator generates for a Rails 3 application, try to run the spec licenses_generator_spec.rb with rspec 2 as follows:

In the file licenses_generator_spec.rb make the following change config.remove_temp_dir = false This will prevent the rails /tmp dir from being deleted after the test run, so you can inspect what is generated in the Rails app.

Now run the generator spec to see the result: $ rspec spec/generators/cancan/licenses_generator_spec.rb

License Generator

Generates a single license in app/licenses

rails g cancan:license [NAME]

Options

  • --creates : The models that have 'creates' permission for the holder of this license
  • --owns : The models that have 'owns' permission for the holder of this license
  • --manages : The models that have 'manages' permission for the holder of this license
  • --read : The models that have 'read' permission for the holder of this license

Run examples:

Generate licenses:

$ rails g cancan:license blog_editing --owns article post --read blog --licenses blogging

Permit Generator

Generates a single license in app/permits

rails g cancan:permit [ROLE]

Options

  • --creates : The models that have 'creates' permission for the holder of this license
  • --owns : The models that have 'owns' permission for the holder of this license
  • --manages : The models that have 'manages' permission for the holder of this license
  • --read : The models that have 'read' permission for the holder of this license

Run examples:

Generate licenses:

$ rails g cancan:permit editor --owns article post --read blog --licenses blog_editing