Module: Chanko::Unit::ClassMethods

Defined in:
lib/chanko/test.rb,
lib/chanko/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/chanko/unit.rb', line 13

def current_scope
  @current_scope
end

Instance Method Details

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

Returns:

  • (Boolean)


44
45
46
# File 'lib/chanko/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/chanko/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/chanko/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/chanko/unit.rb', line 48

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

#extenderObject



100
101
102
# File 'lib/chanko/unit.rb', line 100

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

#find_function(identifier, label) ⇒ Object



77
78
79
80
81
82
# File 'lib/chanko/unit.rb', line 77

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/chanko/unit.rb', line 23

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

#functionsObject



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

def functions
  scopes[current_scope]
end

#helpers(&block) ⇒ Object



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

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

#models(&block) ⇒ Object



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

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

#none(*labels) ⇒ Object



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

def none(*labels)
  ActiveIf::None.new(*labels)
end

#raise_errorObject Also known as: propagates_errors



56
57
58
# File 'lib/chanko/unit.rb', line 56

def raise_error
  @raise_error = true
end

#raise_error?Boolean

Returns:

  • (Boolean)


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

def raise_error?
  @raise_error
end

#resolverObject



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

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

#scope(identifier) ⇒ Object



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

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

#scopesObject



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

def scopes
  @scopes ||= {}
end

#shared(label, &block) ⇒ Object



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

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

#shared_methodsObject



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

def shared_methods
  @shared_methods ||= {}
end

#to_prefixObject



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

def to_prefix
  UnitProxy.generate_prefix(unit_name)
end

#unit_nameObject



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

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

#view_pathObject



73
74
75
# File 'lib/chanko/unit.rb', line 73

def view_path
  Rails.root.join("#{Config.units_directory_path}/#{unit_name}/views").to_s
end