Module: ActiveFacts::Generators::RubyTraits::FactType

Defined in:
lib/activefacts/generators/traits/ruby.rb

Instance Method Summary collapse

Instance Method Details

#fact_rolesObject

An objectified fact type has internal roles that are always “has_one”:



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/activefacts/generators/traits/ruby.rb', line 185

def fact_roles
  raise "Fact #{describe} type is not objectified" unless entity_type
         all_role.sort_by do |role|
    role.preferred_role_name(entity_type)
  end.
  map do |role| 
    role_name = role.preferred_role_name(entity_type)
    one_to_one = role.all_role_ref.detect{|rr|
      rr.role_sequence.all_role_ref.size == 1 &&
      rr.role_sequence.all_presence_constraint.detect{|pc|
	pc.max_frequency == 1
      }
    }
    counterpart_role_method = (one_to_one ? "" : "all_") + 
      entity_type.oo_default_role_name +
      (role_name != role.object_type.oo_default_role_name ? "_as_#{role_name}" : '')
    role.as_binary(role_name, role.object_type, true, one_to_one, nil, nil, counterpart_role_method)
  end.
  join('')
end