Module: StrongConcerns

Defined in:
lib/strong_concerns/intermediate.rb,
lib/strong_concerns.rb,
lib/strong_concerns/version.rb,
lib/strong_concerns/reflection.rb

Overview

two way proxy

Defined Under Namespace

Modules: ClassMethods, InstanceMethods, Reflection Classes: Intermediate, Role, RoleNotActive

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



27
28
29
30
31
32
# File 'lib/strong_concerns.rb', line 27

def self.extended(base)
  base.send(:extend, Reflection)
  base.send(:extend, ClassMethods)
  base.send(:include, InstanceMethods)
  super
end

Instance Method Details

#class_concern(mod, options) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/strong_concerns.rb', line 62

def class_concern(mod, options)
  self.add_class_role(mod, options)
  options.fetch(:exports_methods).each do |meth|
    self.define_singleton_method meth do |*args, &block|
	inter = role_instance(mod)
	unless inter.active?
 raise RoleNotActive.new("Your call method <#{meth}> of inactive role <#{mod.name}>!")
	end
	inter.inactivate
	inter.send(meth,*args, &block)
    end
  end
end

#concern(mod, options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/strong_concerns.rb', line 34

def concern(mod, options)
  self.add_instance_role(mod, options)
  options.fetch(:exports_methods).each do |meth|
    self.send(:define_method, meth) do |*args, &block|
	inter = role_instance(mod)
	unless inter.active?
 raise RoleNotActive.new("Your call method <#{meth}> of inactive role <#{mod.name}>!")
	end
	inter.send(meth,*args, &block)
    end
  end
end