Class: Unimatrix::Authorization::Parser

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

Instance Method Summary collapse

Constructor Details

#initialize(content = {}) {|_self| ... } ⇒ Parser

Returns a new instance of Parser.

Yields:

  • (_self)

Yield Parameters:



5
6
7
8
# File 'lib/unimatrix/authorization/parser.rb', line 5

def initialize( content = {} )
  @content = content
  yield self if block_given?
end

Instance Method Details

#nameObject



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

def name
  @content.keys.present? ? @content.keys.first : nil
end

#parse_resource(name, attributes) ⇒ Object



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

def parse_resource( name, attributes )
  resource = nil

  if attributes.present?
    class_name = name.singularize.camelize
    object_class = Unimatrix::Authorization.const_get( class_name ) rescue nil

    if object_class.present?
      resource = object_class.new( attributes )
    end
  end
  resource
end

#resourcesObject



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

def resources
  result = nil

  unless self.name.blank?
    if @content[ 'error' ]
      result = parse_resource( name, @content )
    else
      result = @content[ name ].map do | attributes |
        self.parse_resource( name, attributes )
      end
    end
  end
  result
end

#type_nameObject



14
15
16
# File 'lib/unimatrix/authorization/parser.rb', line 14

def type_name
  self.name.present? ? name.singularize : nil
end