Sha256: 80d26e3465e1a49c6488bb5c40e4e4fdd1659fbc8a8549473a2bef294766bcae

Contents?: true

Size: 709 Bytes

Versions: 4

Compression:

Stored size: 709 Bytes

Contents

# frozen_string_literal: true

module NCMB
  class Role < NCMB::Object
    include NCMB
    
    def initialize(name)
      if name.is_a? Hash
        @fields = name
      else
        @fields = {
          roleName: name
        }
      end
      @fields[:acl] = NCMB::Acl.new(@fields[:acl])
    end
    
    def self.find_or_create(name)
      d = NCMB::DataStore.new('role')
      d.path = NCMB::Role.new(name).base_path
      role = d.where('roleName', name).limit(1).get.first
      role ? NCMB::Role.new(role.fields) : NCMB::Role.new(name).save()
    end
    
    def name
      "role:#{@fields[:roleName]}"
    end
    
    def base_path
      path = "/#{@@client.api_version}/roles"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ncmb-ruby-client-0.1.7 lib/ncmb/role.rb
ncmb-ruby-client-0.1.6 lib/ncmb/role.rb
ncmb-ruby-client-0.1.5 lib/ncmb/role.rb
ncmb-ruby-client-0.1.4 lib/ncmb/role.rb