Class: Vigia::Adapter::Structure

Inherits:
Object
  • Object
show all
Defined in:
lib/vigia/adapter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter, template) ⇒ Structure

Returns a new instance of Structure.



44
45
46
47
48
49
# File 'lib/vigia/adapter.rb', line 44

def initialize(adapter, template)
  @adapter   = adapter
  @template  = template
  @groups    = {}
  @contexts  = {}
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



42
43
44
# File 'lib/vigia/adapter.rb', line 42

def adapter
  @adapter
end

#contextsObject (readonly)

Returns the value of attribute contexts.



42
43
44
# File 'lib/vigia/adapter.rb', line 42

def contexts
  @contexts
end

#groupsObject (readonly)

Returns the value of attribute groups.



42
43
44
# File 'lib/vigia/adapter.rb', line 42

def groups
  @groups
end

#templateObject (readonly)

Returns the value of attribute template.



42
43
44
# File 'lib/vigia/adapter.rb', line 42

def template
  @template
end

Class Method Details

.generate(adapter, structure) ⇒ Object



35
36
37
38
39
# File 'lib/vigia/adapter.rb', line 35

def generate(adapter, structure)
  instance = new(adapter, structure)
  instance.preload
  instance
end

Instance Method Details

#after_initialize(&block) ⇒ Object



58
59
60
# File 'lib/vigia/adapter.rb', line 58

def after_initialize(&block)
  adapter.instance_exec(&block)
end

#context(name, options = {}) ⇒ Object



66
67
68
# File 'lib/vigia/adapter.rb', line 66

def context(name, options = {})
  @contexts.merge!(name => options)
end

#group(name, options = {}) ⇒ Object



62
63
64
# File 'lib/vigia/adapter.rb', line 62

def group(name, options = {})
  @groups.merge!(name => options)
end

#preloadObject



51
52
53
54
55
56
# File 'lib/vigia/adapter.rb', line 51

def preload
  instance_exec(&template)

  groups.each   { |name, options| Vigia::Sail::Group.register(name, options) }
  contexts.each { |name, options| Vigia::Sail::Context.register(name, options) }
end