Class: Aegis::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/aegis/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



10
11
12
# File 'lib/aegis/parser.rb', line 10

def initialize
  @atoms = []
end

Instance Attribute Details

#atomsObject (readonly)

Returns the value of attribute atoms.



4
5
6
# File 'lib/aegis/parser.rb', line 4

def atoms
  @atoms
end

Class Method Details

.parse(&block) ⇒ Object



6
7
8
# File 'lib/aegis/parser.rb', line 6

def self.parse(&block)
  Aegis::Parser.new.parse(&block)
end

Instance Method Details

#action(*args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/aegis/parser.rb', line 19

def action(*args, &block)
  if block && block.arity > 0
    # useful warning for people upgrading from Aegis 2
    raise Aegis::InvalidSyntax, "Action blocks do not take block arguments in Aegis 2. allow/deny blocks do."
  end
  split_definitions(*args) do |name, options|
    @atoms.push({
      :type => :action,
      :name => name.to_s,
      :options => options,
      :children => Aegis::Parser.parse(&block)
    })
  end
end

#allow(*args, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/aegis/parser.rb', line 67

def allow(*args, &block)
  split_definitions(*args) do |role_name, options|
    @atoms.push({
      :type => :allow,
      :role_name => role_name.to_s,
      :block => block
    })
  end
end

#deny(*args, &block) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/aegis/parser.rb', line 77

def deny(*args, &block)
  split_definitions(*args) do |role_name, options|
    @atoms.push({
      :type => :deny,
      :role_name => role_name.to_s,
      :block => block
    })
  end
end

#namespace(*args, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/aegis/parser.rb', line 34

def namespace(*args, &block)
  split_definitions(*args) do |name, options|
    @atoms.push({
      :type => :namespace,
      :name => name.to_s,
      :options => options,
      :children => Aegis::Parser.parse(&block)
    })
  end
end

#parse(&block) ⇒ Object



14
15
16
17
# File 'lib/aegis/parser.rb', line 14

def parse(&block)
  instance_eval(&block) if block
  atoms
end

#reading(&block) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/aegis/parser.rb', line 87

def reading(&block)
  block or raise Aegis::InvalidSyntax, "missing block"
  @atoms.push({
    :type => :reading,
    :children => Aegis::Parser.parse(&block)
  })
end

#resource(*args, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/aegis/parser.rb', line 45

def resource(*args, &block)
  split_definitions(*args) do |name, options|
    @atoms.push({
      :type => :resource,
      :name => name.to_s,
      :options => options,
      :children => Aegis::Parser.parse(&block)
    })
  end
end

#resources(*args, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/aegis/parser.rb', line 56

def resources(*args, &block)
  split_definitions(*args) do |name, options|
    @atoms.push({
      :type => :resources,
      :name => name.to_s,
      :options => options,
      :children => Aegis::Parser.parse(&block)
    })
  end
end

#writing(&block) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/aegis/parser.rb', line 95

def writing(&block)
  block or raise Aegis::InvalidSyntax, "missing block"
  @atoms.push({
    :type => :writing,
    :children => Aegis::Parser.parse(&block)
  })
end