Class: Mxrb::Dsl::EntityBuilder
- Inherits:
-
Object
- Object
- Mxrb::Dsl::EntityBuilder
- Defined in:
- lib/mxrb/dsl/builder.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- ATTR_TYPES =
%i[string integer long float decimal boolean datetime autonumber hashstring binary enum].freeze
- ASSOCIATION_TYPES =
%i[Reference ReferenceSet].freeze
- ASSOCIATION_OWNERS =
%i[Default Both].freeze
- ASSOCIATION_STORAGE_FORMATS =
%i[Column Table].freeze
- CARDINALITIES =
{ many_to_one: %i[Reference Default], one_to_one: %i[Reference Both], many_to_many: %i[ReferenceSet Default] }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#access_rule(*roles, create: false, delete: false, read: :none, write: :none, xpath: "", default_rights: nil, members: nil) ⇒ Object
access_rule "Module.Role", create: true, delete: false, read: :all, write: [:Name].
- #association(target, type: :Reference, owner: :Default, name: nil, cardinality: nil, documentation: '', parent_delete: :NoAction, child_delete: :NoAction, storage_format: nil) ⇒ Object
- #documentation(d) ⇒ Object
- #generalizes(entity) ⇒ Object
- #index(*attributes, include_offline: false, ascending: true) ⇒ Object
-
#initialize(name) ⇒ EntityBuilder
constructor
A new instance of EntityBuilder.
- #non_persistent! ⇒ Object
- #system_members(owner: false, created_date: false, changed_date: false, changed_by: false) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name) ⇒ EntityBuilder
Returns a new instance of EntityBuilder.
981 982 983 984 985 986 987 988 989 990 991 992 |
# File 'lib/mxrb/dsl/builder.rb', line 981 def initialize(name) @name = name.to_s @attributes = [] @persistable = true @doc = "" @associations = [] @lifecycle = nil @access_rules = nil @generalization = nil @system_members = nil @indexes = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
979 980 981 |
# File 'lib/mxrb/dsl/builder.rb', line 979 def name @name end |
Instance Method Details
#access_rule(*roles, create: false, delete: false, read: :none, write: :none, xpath: "", default_rights: nil, members: nil) ⇒ Object
access_rule "Module.Role", create: true, delete: false, read: :all, write: [:Name]
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 |
# File 'lib/mxrb/dsl/builder.rb', line 1066 def access_rule(*roles, create: false, delete: false, read: :none, write: :none, xpath: "", default_rights: nil, members: nil) @access_rules ||= [] @access_rules << { roles: roles.map(&:to_s), create: create, delete: delete, read: normalize_access(read), write: normalize_access(write), xpath: xpath.to_s, default_rights: default_rights&.to_s, members: members&.map { _1.transform_keys(&:to_sym) } } end |
#association(target, type: :Reference, owner: :Default, name: nil, cardinality: nil, documentation: '', parent_delete: :NoAction, child_delete: :NoAction, storage_format: nil) ⇒ Object
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 |
# File 'lib/mxrb/dsl/builder.rb', line 1030 def association(target, type: :Reference, owner: :Default, name: nil, cardinality: nil, documentation: '', parent_delete: :NoAction, child_delete: :NoAction, storage_format: nil) if cardinality type, owner = CARDINALITIES.fetch(cardinality.to_sym) do raise ArgumentError, 'cardinality must be :many_to_one, :one_to_one, or :many_to_many' end end type = type.to_sym owner = owner.to_sym unless ASSOCIATION_TYPES.include?(type) raise ArgumentError, "association type must be Reference or ReferenceSet" end raise ArgumentError, "association owner must be Default or Both" unless ASSOCIATION_OWNERS.include?(owner) storage_format = normalize_association_storage_format(storage_format) @associations << { name: (name || "#{@name}_#{target}").to_s, target: target.to_s, type: type, owner: owner, documentation: documentation.to_s, parent_delete: parent_delete.to_sym, child_delete: child_delete.to_sym, storage_format: storage_format } end |
#documentation(d) ⇒ Object
1001 |
# File 'lib/mxrb/dsl/builder.rb', line 1001 def documentation(d) = (@doc = d) |
#generalizes(entity) ⇒ Object
1003 1004 1005 |
# File 'lib/mxrb/dsl/builder.rb', line 1003 def generalizes(entity) @generalization = entity.to_s end |
#index(*attributes, include_offline: false, ascending: true) ⇒ Object
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 |
# File 'lib/mxrb/dsl/builder.rb', line 1014 def index(*attributes, include_offline: false, ascending: true) members = attributes.flatten.map(&:to_s) raise ArgumentError, 'index requires at least one attribute' if members.empty? @indexes ||= [] directions = Array(ascending) if directions.size != 1 && directions.size != members.size raise ArgumentError, 'ascending must be one boolean or one value per indexed attribute' end directions *= members.size if directions.size == 1 @indexes << { attributes: members, ascending: directions.map { _1 == true }, include_offline: include_offline == true } end |
#non_persistent! ⇒ Object
1000 |
# File 'lib/mxrb/dsl/builder.rb', line 1000 def non_persistent! = (@persistable = false) |
#system_members(owner: false, created_date: false, changed_date: false, changed_by: false) ⇒ Object
1007 1008 1009 1010 1011 1012 |
# File 'lib/mxrb/dsl/builder.rb', line 1007 def system_members(owner: false, created_date: false, changed_date: false, changed_by: false) @system_members = { owner: owner, created_date: created_date, changed_date: changed_date, changed_by: changed_by } end |
#to_h ⇒ Object
1081 1082 1083 1084 1085 1086 1087 1088 |
# File 'lib/mxrb/dsl/builder.rb', line 1081 def to_h { name: @name, persistable: @persistable, documentation: @doc, attributes: @attributes, associations: @associations, lifecycle: @lifecycle, access_rules: @access_rules, generalization: @generalization, system_members: @system_members, indexes: @indexes } end |