Module: Faalis::Permissions::ClassMethods

Defined in:
lib/faalis/permissions.rb

Constant Summary collapse

@@permissions =

Default permission hash

{
  :read => nil,
  :update => nil,
  :create => nil,
  :destroy => nil,
}
@@only_owner =
false

Instance Method Summary collapse

Instance Method Details

#only_his_objectsObject

This force user to have access to resources which is his.



62
63
64
# File 'lib/faalis/permissions.rb', line 62

def only_his_objects
  @@only_owner = true
end

#only_his_objects?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/faalis/permissions.rb', line 66

def only_his_objects?
  @@only_owner
end

#permission_strings(model) ⇒ Object

Returns an array of strings representation of permissions.

Returns:

  • an array of strings representation of permissions



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/faalis/permissions.rb', line 19

def permission_strings(model)
  strings = []
  model_name = model.to_s
  humanize_name = ActiveModel::Name.new(model).human
  if model.respond_to? :model_name
    model_name = model.model_name
    humanize_name = model_name.human
  end
  @@permissions.each do |key, value|
    strings << {
      :name => "#{key}|#{model_name}",
      :string => _("can %s %s") % [_(key.to_s), humanize_name]
    }
  end
  strings
end

#permissions(*args) ⇒ Object

Define permissions using this method



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/faalis/permissions.rb', line 41

def permissions(*args)

  args.each do |permission|
    if permission.class == Symbol
      if not @@permissions.include? permission
        @@permission[permission] = nil

      elsif permission.class == Hash

        permission.each do |key, value|
          @@permissions[key.to_sym] = value
        end

      end
    end


  end
end

#possible_permissionsObject



36
37
38
# File 'lib/faalis/permissions.rb', line 36

def possible_permissions
  @@permissions.keys
end