Class: Bali::MapRulesDsl

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

Overview

grand scheme of things begin here

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMapRulesDsl

Returns a new instance of MapRulesDsl.



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

def initialize
  @@lock ||= Mutex.new
end

Instance Attribute Details

#current_rule_classObject

Returns the value of attribute current_rule_class.



3
4
5
# File 'lib/bali/dsl/map_rules_dsl.rb', line 3

def current_rule_class
  @current_rule_class
end

Instance Method Details

#can(*params) ⇒ Object



46
47
48
# File 'lib/bali/dsl/map_rules_dsl.rb', line 46

def can(*params)
  fail Bali::DslError, "can block must be within role block"
end

#can_all(*params) ⇒ Object



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

def can_all(*params)
  fail Bali::DslError, "can_all block must be within role block"
end

#cannot(*params) ⇒ Object



55
56
57
# File 'lib/bali/dsl/map_rules_dsl.rb', line 55

def cannot(*params)
  fail Bali::DslError, "cant block must be within role block"
end

#cannot_all(*params) ⇒ Object



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

def cannot_all(*params)
  fail Bali::DslError, "cant_all block must be within role block"
end

#cant(*params) ⇒ Object



50
51
52
53
# File 'lib/bali/dsl/map_rules_dsl.rb', line 50

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

#cant_all(*params) ⇒ Object



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

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

#clear_rulesObject



63
64
65
# File 'lib/bali/dsl/map_rules_dsl.rb', line 63

def clear_rules
  fail Bali::DslError, "clear_rules must be called within role block"
end

#describe(*params) ⇒ Object



38
39
40
# File 'lib/bali/dsl/map_rules_dsl.rb', line 38

def describe(*params)
  fail Bali::DslError, "describe block must be within rules_for block"
end

#role(*params) ⇒ Object



42
43
44
# File 'lib/bali/dsl/map_rules_dsl.rb', line 42

def role(*params)
  fail Bali::DslError, "role block must be within rules_for block"
end

#roles_for(subtarget_class, field_name) ⇒ Object

subtarget_class is the subtarget’s class definition field_name is the field that will be consulted when instantiated object of this class is passed in can? or cant?



33
34
35
36
# File 'lib/bali/dsl/map_rules_dsl.rb', line 33

def roles_for(subtarget_class, field_name)
  Bali::TRANSLATED_SUBTARGET_ROLES[subtarget_class.to_s] = field_name
  nil
end

#rules_for(target_class, options_hash = {}, &block) ⇒ Object

defining rules



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bali/dsl/map_rules_dsl.rb', line 10

def rules_for(target_class, options_hash = {}, &block)
  @@lock.synchronize do
    self.current_rule_class = Bali::RuleClass.new(target_class)

    parent_class = options_hash[:inherits] || options_hash["inherits"]
    if parent_class 
      # in case there is inherits specification
      parent_is_class = parent_class.class
      fail Bali::DslError, 'inherits must take a class' unless parent_is_class
      rule_class_from_parent = Bali::Integrator::RuleClass.for(parent_class)
      fail Bali::DslError, "not yet defined a rule class for #{parent_class}" if rule_class_from_parent.nil?
      self.current_rule_class = rule_class_from_parent.clone(target_class: target_class)
    end

    Bali::RulesForDsl.new(self).instance_eval(&block)

    # done processing the block, now add the rule class
    Bali::Integrator::RuleClass.add(self.current_rule_class)
  end
end