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
-
#oql_view(source: nil, query: nil) ⇒ Object
Marks an entity as an OQL-backed view.
- #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.
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 |
# File 'lib/mxrb/dsl/builder.rb', line 1068 def initialize(name) @name = name.to_s @attributes = [] @persistable = true @doc = "" @associations = [] @lifecycle = nil @access_rules = nil @generalization = nil @system_members = nil @indexes = nil @oql_view = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
1066 1067 1068 |
# File 'lib/mxrb/dsl/builder.rb', line 1066 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]
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 |
# File 'lib/mxrb/dsl/builder.rb', line 1164 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
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 |
# File 'lib/mxrb/dsl/builder.rb', line 1128 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
1089 |
# File 'lib/mxrb/dsl/builder.rb', line 1089 def documentation(d) = (@doc = d) |
#generalizes(entity) ⇒ Object
1101 1102 1103 |
# File 'lib/mxrb/dsl/builder.rb', line 1101 def generalizes(entity) @generalization = entity.to_s end |
#index(*attributes, include_offline: false, ascending: true) ⇒ Object
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
# File 'lib/mxrb/dsl/builder.rb', line 1112 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
1088 |
# File 'lib/mxrb/dsl/builder.rb', line 1088 def non_persistent! = (@persistable = false) |
#oql_view(source: nil, query: nil) ⇒ Object
Marks an entity as an OQL-backed view. Modern Mendix projects keep the query in a separate ViewEntitySourceDocument; older projects may keep it directly on the embedded entity.
1094 1095 1096 1097 1098 1099 |
# File 'lib/mxrb/dsl/builder.rb', line 1094 def oql_view(source: nil, query: nil) raise ArgumentError, 'oql_view requires source or query' if source.nil? && query.nil? @oql_view = { source: source&.to_s, query: query&.to_s }.compact @persistable = false end |
#system_members(owner: false, created_date: false, changed_date: false, changed_by: false) ⇒ Object
1105 1106 1107 1108 1109 1110 |
# File 'lib/mxrb/dsl/builder.rb', line 1105 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
1179 1180 1181 1182 1183 1184 1185 1186 |
# File 'lib/mxrb/dsl/builder.rb', line 1179 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, oql_view: @oql_view } end |