Sha256: 6c67f6743ef673e0a419664683122dcbc68b5865e18944bb352af0b8691574e3

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module NCMB
  class Acl < NCMB::Object
    include NCMB
    
    def initialize(params = nil)
      @fields = {'*': {
          read: true,
          write: true
        }
      }
      if params
        @fields = @fields.merge(params)
      end
    end
    
    def to_json(a = "")
      params = {}
      @fields.each do |key, value|
        params[key.to_sym] = {} if value[:read] || value[:write]
        [:read, :write].each do |name|
          params[key.to_sym][name] = true if value[name]
        end
      end
      params.to_json
    end
    
    def public(read_or_write, value = true)
      @fields['*'.to_sym][read_or_write.to_sym] = value
    end
    
    def user(user, read_or_write, value = true)
      @fields[user.objectId.to_sym] = {read: true, write: true} unless @fields[user.objectId.to_sym]
      @fields[user.objectId.to_sym][read_or_write.to_sym] = value
    end
    
    def role(role, read_or_write, value = true)
      @fields[role.name.to_sym] = {read: true, write: true} unless @fields[role.name.to_sym]
      @fields[role.name.to_sym][read_or_write.to_sym] = value
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ncmb-ruby-client-0.1.1 lib/ncmb/acl.rb
ncmb-ruby-client-0.1.0 lib/ncmb/acl.rb