Sha256: 1573bb811d6aa320d7897ce39fa14533e760663cd6c56bf821326505d662c6df

Contents?: true

Size: 990 Bytes

Versions: 28

Compression:

Stored size: 990 Bytes

Contents

class Miam::DSL::Context::User
  include Miam::TemplateHelper

  def initialize(context, name, &block)
    @user_name = name
    @context = context.merge(: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

28 entries across 28 versions & 1 rubygems

Version Path
miam-0.2.5.beta1 lib/miam/dsl/context/user.rb
miam-0.2.4 lib/miam/dsl/context/user.rb
miam-0.2.4.beta18 lib/miam/dsl/context/user.rb
miam-0.2.4.beta17 lib/miam/dsl/context/user.rb
miam-0.2.4.beta16 lib/miam/dsl/context/user.rb
miam-0.2.4.beta15 lib/miam/dsl/context/user.rb
miam-0.2.4.beta14 lib/miam/dsl/context/user.rb
miam-0.2.4.beta13 lib/miam/dsl/context/user.rb
miam-0.2.4.beta12 lib/miam/dsl/context/user.rb
miam-0.2.4.beta11 lib/miam/dsl/context/user.rb
miam-0.2.4.beta10 lib/miam/dsl/context/user.rb
miam-0.2.4.beta9 lib/miam/dsl/context/user.rb
miam-0.2.4.beta8 lib/miam/dsl/context/user.rb
miam-0.2.4.beta7 lib/miam/dsl/context/user.rb
miam-0.2.4.beta6 lib/miam/dsl/context/user.rb
miam-0.2.4.beta5 lib/miam/dsl/context/user.rb
miam-0.2.4.beta4 lib/miam/dsl/context/user.rb
miam-0.2.4.beta3 lib/miam/dsl/context/user.rb
miam-0.2.4.beta2 lib/miam/dsl/context/user.rb
miam-0.2.4.beta lib/miam/dsl/context/user.rb