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:



36
37
38
# File 'lib/bali/dsl/map_rules_dsl.rb', line 36

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

#can_all(*params) ⇒ Object

Raises:



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

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

#cant(*params) ⇒ Object

Raises:



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

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

#cant_all(*params) ⇒ Object

Raises:



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

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

#describe(*params) ⇒ Object

Raises:



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

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:



24
25
26
27
28
29
30
# File 'lib/bali/dsl/map_rules_dsl.rb', line 24

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, target_alias_hash = {}, &block) ⇒ Object

defining rules



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bali/dsl/map_rules_dsl.rb', line 10

def rules_for(target_class, target_alias_hash = {}, &block)
  @@lock.synchronize do
    self.current_rule_class = Bali::RuleClass.new(target_class)
    self.current_rule_class.alias_name = target_alias_hash[:as] || target_alias_hash["as"]

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

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