Sha256: b554470cf3b716c12428b5bb059ba3444f22b3b78544802d3063a1a5f352b89e
Contents?: true
Size: 1.28 KB
Versions: 19
Compression:
Stored size: 1.28 KB
Contents
require 'active_support/core_ext/string/inflections' module UniverseCompiler module Entity module RelationsManagement def has_one(entity_type, name: nil) case entity_type when Class name = name.nil? ? entity_type.entity_type : name.to_sym define_constraint name, :has_one, entity_type.entity_type when Symbol, String name = name.nil? ? entity_type.to_sym : name.to_sym define_constraint name, :has_one, entity_type.to_sym end end def has_many(entity_type, name: nil) name = case entity_type when Class name.nil? ? entity_type.entity_type : name.to_sym when Symbol, String name.nil? ? entity_type.to_sym : name.to_sym end field_name = name.to_s.pluralize.to_sym case entity_type when Class define_constraint field_name, :has_many, entity_type.entity_type when Symbol, String define_constraint field_name, :has_many, entity_type.to_sym end end def entity_type_relations fields_constraints.select do |_, constraints| constraints.keys.include? :has_one or constraints.keys.include? :has_many end end end end end
Version data entries
19 entries across 19 versions & 1 rubygems