Sha256: 43f80112d60b583bbda1ec1a387eb7dbfca25532b34137e4ae245d33210eabfd

Contents?: true

Size: 1005 Bytes

Versions: 14

Compression:

Stored size: 1005 Bytes

Contents

module JasonObjectListProperties
  def self.included(base)
    base.extend(MetaListProperties)
  end
  
  module MetaListProperties
    def create_member_list list_name, list_class, list_type
      list = {}
      list = self.send(:class_variable_get, :@@lists) if self.class_variable_defined? :@@lists
      list[list_name] = [list_class, list_type]
      self.send(:class_variable_set, "@@lists", list)

      define_method(list_name) do
        #puts "Looking at the #{list_name.to_s} list, which is full of #{list_type.name}s"
        Medea::JasonListProperty.new self, list_name, list_class, list_type
      end
    end

    def has_many list_name, list_class
      create_member_list list_name, list_class, :reference
    end

    def owns_many list_name, list_class
      create_member_list list_name, list_class, :value

      #also modify the items in the list so that they know that they're owned
      #list_type.class_variable_set :@@owner, self
      list_class.owned = true
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
medea-0.4.0 lib/medea/list_properties.rb
medea-0.3.7 lib/medea/list_properties.rb
medea-0.3.6 lib/medea/list_properties.rb
medea-0.3.5 lib/medea/list_properties.rb
medea-0.3.4 lib/medea/list_properties.rb
medea-0.3.3 lib/medea/list_properties.rb
medea-0.3.2 lib/medea/list_properties.rb
medea-0.3.1 lib/medea/list_properties.rb
medea-0.3.0 lib/medea/list_properties.rb
medea-0.2.31 lib/medea/list_properties.rb
medea-0.2.30 lib/medea/list_properties.rb
medea-0.2.29 lib/medea/list_properties.rb
medea-0.2.28 lib/medea/list_properties.rb
Medea-0.2.27 lib/medea/list_properties.rb