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

Raises:



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

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

#can_all(*params) ⇒ Object

Raises:



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

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

#cannot(*params) ⇒ Object

Raises:



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

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

#cannot_all(*params) ⇒ Object

Raises:



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

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

#cant(*params) ⇒ Object



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

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



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

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

Raises:



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

def clear_rules
  raise Bali::DslError, "clear_rules must be called within describe block"
end

#describe(*params) ⇒ Object

Raises:



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

def describe(*params)
  raise Bali::DslError, "describe 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?

Raises:



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

def roles_for(subtarget_class, field_name)
  raise Bali::DslError, "Subtarget must be a class" unless subtarget_class.is_a?(Class)
  raise Bali::DslError, "Field name must be a symbol/string" if !(field_name.is_a?(Symbol) || field_name.is_a?(String))

  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
    raise Bali::DslError "rules_for must describe a target which is a class" unless target_class.is_a?(Class)
    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
      raise Bali::DslError, "inherits must take a class" unless parent_class.is_a?(Class)
      rule_class_from_parent = Bali::Integrators::Rule.rule_class_for(parent_class)
      raise 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::Integrators::Rule.add_rule_class(self.current_rule_class)
  end
end