Sha256: 481a3a3e5e71920f3f4db0bf7c1e3a9793416f2fc388bd8d99dcdaac170ff85b

Contents?: true

Size: 1005 Bytes

Versions: 2

Compression:

Stored size: 1005 Bytes

Contents

module Datacentred
  module Model
    class Role < OpenStruct
      def initialize(params)
        params.delete("links")
        params["created_at"] = Time.parse params["created_at"]
        params["updated_at"] = Time.parse params["updated_at"]
        super(params)
      end

      def self.all
        Request::Roles.list.map{|role| new(role) }
      end

      def self.find(id)
        new Request::Roles.show(id)
      end

      def self.create(params)
        new Request::Roles.create(params)
      end

      def self.update(id, params)
        new Request::Roles.update(id, params)
      end

      def self.delete(id)
        Request::Roles.destroy(id)
      end

      def self.users(id)
        Request::Roles.list_users(id).map{|user| new(user) }
      end

      def self.add_user(role_id, user_id)
        Request::Roles.add_user(role_id, user_id)
      end

      def self.remove_user(role_id, user_id)
        Request::Roles.remove_user(role_id, user_id)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datacentred-0.1.1pre lib/datacentred/model/role.rb
datacentred-0.1.0pre lib/datacentred/model/role.rb