Class: Bali::RulesForDsl

Inherits:
Object
  • Object
show all
Defined in:
lib/bali/dsl/rules_for_dsl.rb

Overview

this class is used to define DSL after rules_for is invoked.

Author:

  • Adam Pahlevi Baihaqi

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map_rules_dsl) ⇒ RulesForDsl

Returns a new instance of RulesForDsl.



12
13
14
15
# File 'lib/bali/dsl/rules_for_dsl.rb', line 12

def initialize(map_rules_dsl)
  @@lock = Mutex.new
  self.map_rules_dsl = map_rules_dsl
end

Instance Attribute Details

#current_rule_groupObject

Returns the value of attribute current_rule_group.



5
6
7
# File 'lib/bali/dsl/rules_for_dsl.rb', line 5

def current_rule_group
  @current_rule_group
end

#current_subtargetsObject

all to be processed subtargets



8
9
10
# File 'lib/bali/dsl/rules_for_dsl.rb', line 8

def current_subtargets
  @current_subtargets
end

#map_rules_dslObject

Returns the value of attribute map_rules_dsl.



4
5
6
# File 'lib/bali/dsl/rules_for_dsl.rb', line 4

def map_rules_dsl
  @map_rules_dsl
end

#shortcut_rulesObject

rules defined with hash can: [] and cannot: []



10
11
12
# File 'lib/bali/dsl/rules_for_dsl.rb', line 10

def shortcut_rules
  @shortcut_rules
end

Instance Method Details

#can(*operations) ⇒ Object



64
65
66
# File 'lib/bali/dsl/rules_for_dsl.rb', line 64

def can(*operations)
  bali_process_auth_rules(:can, operations)
end

#can_allObject



77
78
79
80
# File 'lib/bali/dsl/rules_for_dsl.rb', line 77

def can_all
  self.current_rule_group.zeus = true
  self.current_rule_group.plant = false
end

#cannot(*operations) ⇒ Object



68
69
70
# File 'lib/bali/dsl/rules_for_dsl.rb', line 68

def cannot(*operations)
  bali_process_auth_rules(:cannot, operations)
end

#cannot_allObject



82
83
84
85
# File 'lib/bali/dsl/rules_for_dsl.rb', line 82

def cannot_all
  self.current_rule_group.plant = true
  self.current_rule_group.zeus = false
end

#cant(*operations) ⇒ Object



72
73
74
75
# File 'lib/bali/dsl/rules_for_dsl.rb', line 72

def cant(*operations)
  puts "Deprecation Warning: declaring rules with cant will be deprecated on major release 3.0, use cannot instead"
  cannot(*operations)
end

#cant_allObject



87
88
89
90
# File 'lib/bali/dsl/rules_for_dsl.rb', line 87

def cant_all
  puts "Deprecation Warning: declaring rules with cant_all will be deprecated on major release 3.0, use cannot_all instead"
  cannot_all
end

#clear_rulesObject

clear all defined rules



59
60
61
62
# File 'lib/bali/dsl/rules_for_dsl.rb', line 59

def clear_rules
  self.current_rule_group.clear_rules
  true
end

#describe(*params) ⇒ Object

role



38
39
40
41
42
43
44
45
46
47
# File 'lib/bali/dsl/rules_for_dsl.rb', line 38

def describe(*params)
  puts "Bali Deprecation Warning: describing rules using describe will be deprecated on major release 3.0, use role instead"
  if block_given?
    role(*params) do
      yield
    end
  else
    role(*params)
  end
end

#others(*params) ⇒ Object

others block



50
51
52
53
54
55
56
# File 'lib/bali/dsl/rules_for_dsl.rb', line 50

def others(*params)
  if block_given?
    role("__*__") do
      yield
    end
  end
end

#role(*params) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bali/dsl/rules_for_dsl.rb', line 22

def role(*params)
  @@lock.synchronize do
    bali_scrap_actors(*params)
    bali_scrap_shortcut_rules(*params)
    current_subtargets.each do |subtarget|
      if block_given?
        bali_process_subtarget(subtarget) do
          yield
        end
      else
        bali_process_subtarget(subtarget)
      end
    end
  end
end