Class: MailyHerald::Context::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/maily_herald/context.rb

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ Attributes

Returns a new instance of Attributes.



48
49
50
51
52
# File 'lib/maily_herald/context.rb', line 48

def initialize block
  @attrs = {}
  @node = @parent_node = @attrs
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



79
80
81
# File 'lib/maily_herald/context.rb', line 79

def method_missing(m, *args, &block)
  true
end

Instance Method Details

#attribute(name, &block) ⇒ Object



71
72
73
# File 'lib/maily_herald/context.rb', line 71

def attribute name, &block
  @node[name.to_s] = block
end

#attribute_group(name, &block) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/maily_herald/context.rb', line 63

def attribute_group name, &block
  @parent_node = @node
  @parent_node[name.to_s] ||= {}
  @node = @parent_node[name.to_s]
  yield
  @node = @parent_node
end

#for_dropObject



75
76
77
# File 'lib/maily_herald/context.rb', line 75

def for_drop
  @attrs
end

#setup(entity = nil, subscription = nil) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/maily_herald/context.rb', line 54

def setup entity = nil, subscription = nil
  if entity
    @attrs["subscription"] = Proc.new{ subscription } if subscription
    instance_exec entity, &@block
  else
    instance_eval &@block
  end
end