Sha256: ef4f0ee59772b0db7a6764ac2d653445986dec285f6cf88d8a83713f4bb96708

Contents?: true

Size: 900 Bytes

Versions: 3

Compression:

Stored size: 900 Bytes

Contents

class Miam::DSL::Context::User
  def initialize(name, &block)
    @user_name = name
    @result = {:groups => [], :policies => {}, :attached_managed_policies => []}
    instance_eval(&block)
  end

  attr_reader :result

  private

  def login_profile(value)
    @result[:login_profile] = value
  end

  def groups(*grps)
    @result[:groups].concat(grps.map(&:to_s))
  end

  def policy(name)
    name = name.to_s

    if @result[:policies][name]
      raise "User `#{@user_name}` > Policy `#{name}`: already defined"
    end

    policy_document = yield

    unless policy_document.kind_of?(Hash)
      raise "User `#{@user_name}` > Policy `#{name}`: wrong argument type #{policy_document.class} (expected Hash)"
    end

    @result[:policies][name] = policy_document
  end

  def attached_managed_policies(*policies)
    @result[:attached_managed_policies].concat(policies.map(&:to_s))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
miam-0.2.2.beta lib/miam/dsl/context/user.rb
miam-0.2.1 lib/miam/dsl/context/user.rb
miam-0.2.1.beta2 lib/miam/dsl/context/user.rb