Module: Micon::Managed

Defined in:
lib/micon/managed.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.hook!(klass = Module) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/micon/managed.rb', line 15

def hook! klass = Module
  klass.class_eval do
    def inject attributes
      ::Micon::Managed.inject self, attributes
    end

    def scope scope
      ::Micon::Managed.scope self, scope
    end
  end
end

.inject(klass, attributes) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/micon/managed.rb', line 27

def inject klass, attributes
  raise_without_self "Invalid argument!", Micon unless attributes.is_a? Hash
  attributes.each do |name, specificator|
    raise_without_self "Attribute name should be a Symbol!", Micon unless name.is_a? Symbol        

    if [Class, Module].include? specificator.class
      specificator = specificator.name
    elsif specificator.is_a? Symbol
      specificator = ":#{specificator}"
    else
      specificator = "\"#{specificator}\""
    end

    script = %{\
    def #{name}
::Micon[#{specificator}]
    end

    def #{name}= value
::Micon[#{specificator}] = value
    end}
    klass.class_eval script, __FILE__, __LINE__
  end
end

.scope(klass, scope) ⇒ Object



52
53
54
55
# File 'lib/micon/managed.rb', line 52

def scope klass, scope
  raise_without_self "Micon Name shoul be a Symbol!", Micon unless scope.is_a? Symbol
  ::Micon.register(klass, :scope => scope){klass.new}
end