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, AutomaticRole, Create, Deny, Give, Grant, Include, 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.
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_name ⇒ Object 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_names ⇒ Object
321 322 323 |
# File 'lib/conjur/policy/types/base.rb', line 321 def custom_attribute_names [ ] end |
#id_attribute ⇒ Object
319 |
# File 'lib/conjur/policy/types/base.rb', line 319 def id_attribute; 'id'; end |
#referenced_records ⇒ Object
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
325 326 327 |
# File 'lib/conjur/policy/types/base.rb', line 325 def resource? false end |
#role? ⇒ Boolean
Things aren’t roles by default
315 316 317 |
# File 'lib/conjur/policy/types/base.rb', line 315 def role? false end |