Class: Conjur::Policy::Types::Base
- 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.
Direct Known Subclasses
Ruby::Policy, Create, Deny, Give, Grant, ManagedRole, Member, Permit, Record, Retire, Revoke, Update
Class Method Summary collapse
-
.inherited(cls) ⇒ Object
Hook to register the YAML type.
- .register_yaml_type(simple_name) ⇒ Object
-
.short_name ⇒ Object
(also: simple_name)
The last token in the ::-separated class name.
Instance Method Summary collapse
- #custom_attribute_names ⇒ Object
- #id_attribute ⇒ Object
-
#referenced_records ⇒ Object
Gets all ‘child’ records.
- #resource? ⇒ Boolean
-
#role? ⇒ Boolean
Things aren’t roles by default.
Methods included from InheritableAttribute
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_name ⇒ Object 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_names ⇒ Object
314 315 316 |
# File 'lib/conjur/policy/types/base.rb', line 314 def custom_attribute_names [ ] end |
#id_attribute ⇒ Object
312 |
# File 'lib/conjur/policy/types/base.rb', line 312 def id_attribute; 'id'; end |
#referenced_records ⇒ Object
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
318 319 320 |
# File 'lib/conjur/policy/types/base.rb', line 318 def resource? false end |
#role? ⇒ Boolean
Things aren’t roles by default
308 309 310 |
# File 'lib/conjur/policy/types/base.rb', line 308 def role? false end |