Module: CanCan::Export::Ability

Extended by:
ActiveSupport::Concern
Included in:
Ability
Defined in:
lib/cancan/export/ext/ability.rb

Instance Method Summary collapse

Instance Method Details

#helper_method(*method_names) ⇒ Object



10
11
12
13
14
# File 'lib/cancan/export/ext/ability.rb', line 10

def helper_method(*method_names)
  helper_methods.merge! method_names.map {|method_name|
    [method_name, @@compiler.to_js(method(method_name))]
  }.to_h
end

#helper_methodsObject



16
17
18
# File 'lib/cancan/export/ext/ability.rb', line 16

def helper_methods
  @helpers ||= {}
end

#to_json(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cancan/export/ext/ability.rb', line 20

def to_json(options={})
  {
    rules: @rules.map {|rule|
      rule.compile(self, @@compiler)
    },
    rulesIndex: @rules_index.map {|object, indices|
      [object.to_s, indices]
    }.to_h,
    helpersSource: helper_methods
  }.to_json(options)
end