Class: Typisch::DSL::DerivedObjectContext

Inherits:
ObjectContext show all
Defined in:
lib/typisch/dsl.rb

Instance Attribute Summary

Attributes inherited from ObjectContext

#properties, #property_annotations

Instance Method Summary collapse

Methods inherited from ObjectContext

#annotate, #method_missing, #property

Constructor Details

#initialize(c, original_object_type) ⇒ DerivedObjectContext

Returns a new instance of DerivedObjectContext.



199
200
201
202
# File 'lib/typisch/dsl.rb', line 199

def initialize(c, original_object_type)
  super(c)
  @original_object_type = original_object_type
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Typisch::DSL::ObjectContext

Instance Method Details

#derive_all_propertiesObject

derives all properties from the original type which haven’t already been derived. this is done for you by Typisch::Typed::ClassMethods#register_subtype.



217
218
219
220
221
# File 'lib/typisch/dsl.rb', line 217

def derive_all_properties
  @original_object_type.property_names_to_types.each do |name, type|
    property(name, type) unless @properties[name]
  end
end

#derive_all_properties_except(*props) ⇒ Object



223
224
225
226
227
228
# File 'lib/typisch/dsl.rb', line 223

def derive_all_properties_except(*props)
  @original_object_type.property_names_to_types.each do |name, type|
    next if props.include?(name)
    property(name, type) unless @properties[name]
  end
end

#derive_properties(*names) ⇒ Object



204
205
206
# File 'lib/typisch/dsl.rb', line 204

def derive_properties(*names)
  names.each {|n| derive_property(n)}
end

#derive_property(name, *derive_args, &derive_block) ⇒ Object

use a property from the original object type being derived from



209
210
211
212
213
# File 'lib/typisch/dsl.rb', line 209

def derive_property(name, *derive_args, &derive_block)
  type = @original_object_type[name] or raise "use_property: no such property #{name.inspect} on the original type"
  derived_type = derived_from(type, *derive_args, &derive_block)
  property name, derived_type
end