Module: Nyanko::Unit::ClassMethods

Defined in:
lib/nyanko/test.rb,
lib/nyanko/unit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_scopeObject

Returns the value of attribute current_scope.



13
14
15
# File 'lib/nyanko/unit.rb', line 13

def current_scope
  @current_scope
end

Instance Method Details

#active?(context, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/nyanko/unit.rb', line 44

def active?(context, options = {})
  @active_if.active?(context, options.merge(:unit => self))
end

#active_if(*conditions, &block) ⇒ Object



40
41
42
# File 'lib/nyanko/unit.rb', line 40

def active_if(*conditions, &block)
  @active_if = ActiveIf.new(*conditions, &block)
end

#active_with_activations?(*args) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
# File 'lib/nyanko/test.rb', line 26

def active_with_activations?(*args)
  case Test.activations[unit_name]
  when true
    true
  when false
    false
  else
    active_without_activations?(*args)
  end
end

#any(*labels) ⇒ Object



48
49
50
# File 'lib/nyanko/unit.rb', line 48

def any(*labels)
  ActiveIf::Any.new(*labels)
end

#extenderObject



96
97
98
# File 'lib/nyanko/unit.rb', line 96

def extender
  @extender ||= Extender.new(to_prefix)
end

#find_function(identifier, label) ⇒ Object



73
74
75
76
77
78
# File 'lib/nyanko/unit.rb', line 73

def find_function(identifier, label)
  scope     = ScopeFinder.find(identifier)
  target    = scope.ancestors.find {|klass| scopes[klass] }
  functions = scopes[target]
  functions[label] if functions
end

#function(label, &block) ⇒ Object Also known as: callback



23
24
25
# File 'lib/nyanko/unit.rb', line 23

def function(label, &block)
  functions[label] = Function.new(self, label, &block)
end

#functionsObject



80
81
82
# File 'lib/nyanko/unit.rb', line 80

def functions
  scopes[current_scope]
end

#helpers(&block) ⇒ Object



32
33
34
# File 'lib/nyanko/unit.rb', line 32

def helpers(&block)
  Helper.define(unit_name, &block)
end

#models(&block) ⇒ Object



36
37
38
# File 'lib/nyanko/unit.rb', line 36

def models(&block)
  extender.instance_eval(&block)
end

#raise_errorObject Also known as: propagates_errors



52
53
54
# File 'lib/nyanko/unit.rb', line 52

def raise_error
  @raise_error = true
end

#raise_error?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/nyanko/unit.rb', line 57

def raise_error?
  @raise_error
end

#resolverObject



92
93
94
# File 'lib/nyanko/unit.rb', line 92

def resolver
  @resolver ||= Config.resolver.new(view_path)
end

#scope(identifier) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/nyanko/unit.rb', line 15

def scope(identifier)
  self.current_scope = ScopeFinder.find(identifier)
  scopes[current_scope] ||= {}
  yield
ensure
  self.current_scope = nil
end

#scopesObject



84
85
86
# File 'lib/nyanko/unit.rb', line 84

def scopes
  @scopes ||= {}
end

#shared(label, &block) ⇒ Object



28
29
30
# File 'lib/nyanko/unit.rb', line 28

def shared(label, &block)
  shared_methods[label] = block
end

#shared_methodsObject



88
89
90
# File 'lib/nyanko/unit.rb', line 88

def shared_methods
  @shared_methods ||= {}
end

#to_prefixObject



65
66
67
# File 'lib/nyanko/unit.rb', line 65

def to_prefix
  UnitProxy.generate_prefix(unit_name)
end

#unit_nameObject



61
62
63
# File 'lib/nyanko/unit.rb', line 61

def unit_name
  @unit_name ||= name.underscore.to_sym
end

#view_pathObject



69
70
71
# File 'lib/nyanko/unit.rb', line 69

def view_path
  "#{Config.units_directory_path}/#{unit_name}/views"
end