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.



340
341
342
# File 'lib/conjur/policy/types/base.rb', line 340

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

.register_yaml_type(simple_name) ⇒ Object



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

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.



345
346
347
# File 'lib/conjur/policy/types/base.rb', line 345

def short_name
  self.name.demodulize
end

Instance Method Details

#custom_attribute_namesObject



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

def custom_attribute_names
  [ ]
end

#id_attributeObject



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

def id_attribute; 'id'; end

#referenced_recordsObject

Gets all ‘child’ records.



327
328
329
330
331
332
333
334
335
336
# File 'lib/conjur/policy/types/base.rb', line 327

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)


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

def resource?
  false
end

#role?Boolean

Things aren’t roles by default

Returns:

  • (Boolean)


308
309
310
# File 'lib/conjur/policy/types/base.rb', line 308

def role?
  false
end