Class: Unimatrix::Authorization::Parser
- Inherits:
-
Object
- Object
- Unimatrix::Authorization::Parser
- Defined in:
- lib/unimatrix/authorization/parser.rb
Instance Method Summary collapse
-
#initialize(content = {}, request_path = "") {|_self| ... } ⇒ Parser
constructor
A new instance of Parser.
- #name ⇒ Object
- #parse_resource(name, attributes) ⇒ Object
- #resources ⇒ Object
- #type_name ⇒ Object
Constructor Details
#initialize(content = {}, request_path = "") {|_self| ... } ⇒ Parser
Returns a new instance of Parser.
5 6 7 8 9 |
# File 'lib/unimatrix/authorization/parser.rb', line 5 def initialize( content = {}, request_path = "" ) @content = content @request_path = request_path yield self if block_given? end |
Instance Method Details
#name ⇒ Object
11 12 13 |
# File 'lib/unimatrix/authorization/parser.rb', line 11 def name @request_path[ 1...@request_path.length ] end |
#parse_resource(name, attributes) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/unimatrix/authorization/parser.rb', line 38 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 |
#resources ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/unimatrix/authorization/parser.rb', line 19 def resources result = nil unless self.name.blank? if @content[ 'error' ] result = parse_resource( 'error', @content ) else unless @content[ name ].is_a?( Array ) result = [ parse_resource( name, @content ) ] else result = @content[ name ].map do | attributes | parse_resource( name, attributes ) end end end end result end |
#type_name ⇒ Object
15 16 17 |
# File 'lib/unimatrix/authorization/parser.rb', line 15 def type_name self.name.present? ? name.singularize : nil end |