Sha256: 5a50a7c7a3775b940c3e5f4e4fae1956b8976c69b883dfc3ae76a4b8f0683654

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module NCMB
  class Acl
    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, bol = true)
      @fields['*'.to_sym][read_or_write.to_sym] = bol
    end
    
    # :reek:DuplicateMethodCall { max_calls: 2 }
    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
    
    # :reek:DuplicateMethodCall { max_calls: 2 }
    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

3 entries across 3 versions & 1 rubygems

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