Sha256: 9733b45eeb74542f48bc70fb8e696d53bb147aaae58f435604cd05d0e4ca1e04

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

module Unimatrix::Authorization

  class Parser

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

    def name
      @request_path[ 1...@request_path.length ]
    end

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

    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

    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

  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
unimatrix-3.4.0 lib/unimatrix/authorization/parser.rb
unimatrix-3.3.4 lib/unimatrix/authorization/parser.rb
unimatrix-3.3.3 lib/unimatrix/authorization/parser.rb
unimatrix-3.3.2 lib/unimatrix/authorization/parser.rb
unimatrix-3.3.1 lib/unimatrix/authorization/parser.rb
unimatrix-3.3.0 lib/unimatrix/authorization/parser.rb
unimatrix-3.2.0 lib/unimatrix/authorization/parser.rb
unimatrix-3.1.0 lib/unimatrix/authorization/parser.rb
unimatrix-3.0.0 lib/unimatrix/authorization/parser.rb
unimatrix-2.9.0 lib/unimatrix/authorization/parser.rb
unimatrix-2.8.0 lib/unimatrix/authorization/parser.rb
unimatrix-2.7.1 lib/unimatrix/authorization/parser.rb
unimatrix-2.7.0 lib/unimatrix/authorization/parser.rb