Class: Conjur::Policy::Types::Base

Inherits:
Object
  • Object
show all
Extended by:
AttributeDefinition, InheritableAttribute, TypeChecking
Defined in:
lib/conjur/policy/types/base.rb

Overview

Base class for implementing structured DSL object types such as Role, User, etc.

To define a type:

  • Inherit from this class

  • Define attributes using attribute

Your new type will automatically be registered with the YAML parser with a tag corresponding to the lower-cased short name of the class.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InheritableAttribute

inherit_for, inheritable_attr

Methods included from TypeChecking

expect_array, expect_boolean, expect_hash, expect_integer, expect_layer, expect_member, expect_permission, expect_record, expect_resource, expect_role, expect_string, expect_type, test_resource, test_role

Methods included from AttributeDefinition

attribute, define_field, define_plural_field, field?, yaml_field?, yaml_field_type

Class Method Details

.inherited(cls) ⇒ Object

Hook to register the YAML type.



347
348
349
# File 'lib/conjur/policy/types/base.rb', line 347

def inherited cls
  cls.register_yaml_type cls.short_name.underscore.gsub('_', '-')
end

.register_yaml_type(simple_name) ⇒ Object



358
359
360
# File 'lib/conjur/policy/types/base.rb', line 358

def register_yaml_type simple_name
  ::YAML.add_tag "!#{simple_name}", self
end

.short_nameObject Also known as: simple_name

The last token in the ::-separated class name.



352
353
354
# File 'lib/conjur/policy/types/base.rb', line 352

def short_name
  self.name.demodulize
end

Instance Method Details

#custom_attribute_namesObject



321
322
323
# File 'lib/conjur/policy/types/base.rb', line 321

def custom_attribute_names
  [ ]
end

#id_attributeObject



319
# File 'lib/conjur/policy/types/base.rb', line 319

def id_attribute; 'id'; end

#referenced_recordsObject

Gets all ‘child’ records.



334
335
336
337
338
339
340
341
342
343
# File 'lib/conjur/policy/types/base.rb', line 334

def referenced_records
  result = []
  instance_variables.map do |var|
    value = instance_variable_get var
    Array(value).each do |val|
      result.push val if val.is_a?(Conjur::Policy::Types::Base)
    end
  end
  result.flatten
end

#resource?Boolean

Returns:

  • (Boolean)


325
326
327
# File 'lib/conjur/policy/types/base.rb', line 325

def resource?
  false
end

#role?Boolean

Things aren’t roles by default

Returns:

  • (Boolean)


315
316
317
# File 'lib/conjur/policy/types/base.rb', line 315

def role?
  false
end