Module: ActiveFacts::Generators::RubyTraits::ValueType

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

Instance Method Summary collapse

Instance Method Details

#ruby_definitionObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/activefacts/generators/traits/ruby.rb', line 150

def ruby_definition
  return if name == "_ImplicitBooleanValueType"

  ruby_length = length && length > 0 ? ":length => #{length}" : nil
  ruby_scale = scale && scale > 0 ? ":scale => #{scale}" : nil
  params = [ruby_length,ruby_scale].compact * ", "

  base_type = supertype || self
  base_type_name = base_type.ruby_type_name
  ruby_name = ruby_type_name
  if base_type_name == ruby_name
    base_type_name = '::'+base_type_name
  end

  "  class #{ruby_name} < #{base_type_name}\n" +
  "    value_type #{params}\n" +
  #emit_mapping self if is_table
  (value_constraint ?
    "    restrict #{value_constraint.all_allowed_range_sorted.map{|ar| ar.to_s}*", "}\n" :
    ""
  ) +
  (unit ?
    "    \# REVISIT: #{ruby_name} is in units of #{unit.name}\n" :
    ""
  ) +
  absorbed_roles.map do |role|
    role.ruby_role_definition
  end.
  compact*"" +
  "  end\n\n"
end