Module: Nyanko::Unit::ClassMethods
- Defined in:
- lib/nyanko/test.rb,
lib/nyanko/unit.rb
Instance Attribute Summary collapse
-
#current_scope ⇒ Object
Returns the value of attribute current_scope.
Instance Method Summary collapse
- #active?(context, options = {}) ⇒ Boolean
- #active_if(*conditions, &block) ⇒ Object
- #active_with_activations?(*args) ⇒ Boolean
- #any(*labels) ⇒ Object
- #extender ⇒ Object
- #find_function(identifier, label) ⇒ Object
- #function(label, &block) ⇒ Object (also: #callback)
- #functions ⇒ Object
- #helpers(&block) ⇒ Object
- #models(&block) ⇒ Object
- #raise_error ⇒ Object (also: #propagates_errors)
- #raise_error? ⇒ Boolean
- #resolver ⇒ Object
- #scope(identifier) ⇒ Object
- #scopes ⇒ Object
- #shared(label, &block) ⇒ Object
- #shared_methods ⇒ Object
- #to_prefix ⇒ Object
- #unit_name ⇒ Object
- #view_path ⇒ Object
Instance Attribute Details
#current_scope ⇒ Object
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
44 45 46 |
# File 'lib/nyanko/unit.rb', line 44 def active?(context, = {}) @active_if.active?(context, .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
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 |
#extender ⇒ Object
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 |
#functions ⇒ Object
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_error ⇒ Object 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
57 58 59 |
# File 'lib/nyanko/unit.rb', line 57 def raise_error? @raise_error end |
#resolver ⇒ Object
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 |
#scopes ⇒ Object
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_methods ⇒ Object
88 89 90 |
# File 'lib/nyanko/unit.rb', line 88 def shared_methods @shared_methods ||= {} end |
#to_prefix ⇒ Object
65 66 67 |
# File 'lib/nyanko/unit.rb', line 65 def to_prefix UnitProxy.generate_prefix(unit_name) end |
#unit_name ⇒ Object
61 62 63 |
# File 'lib/nyanko/unit.rb', line 61 def unit_name @unit_name ||= name.underscore.to_sym end |
#view_path ⇒ Object
69 70 71 |
# File 'lib/nyanko/unit.rb', line 69 def view_path "#{Config.units_directory_path}/#{unit_name}/views" end |