Class: CoreData::DataModel

Inherits:
Object
  • Object
show all
Defined in:
lib/core_data/data_model.rb,
lib/core_data/data_model/entity.rb,
lib/core_data/data_model/attribute.rb,
lib/core_data/data_model/relationship.rb

Defined Under Namespace

Classes: Attribute, Entity, Relationship

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_model) ⇒ DataModel

Returns a new instance of DataModel.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/core_data/data_model.rb', line 9

def initialize(data_model)
  loop do
    case data_model
    when File, /^\<\?xml/
      (data_model = ::Nokogiri::XML(data_model)) && redo
    when String
      case data_model
      when /\.xcdatamodeld?$/
        (data_model = Dir[File.join(data_model, '/**/contents')].first) && redo
      else
        (data_model = ::File.read(data_model)) && redo
      end
    when ::Nokogiri::XML::Document
      break
    else
      raise ArgumentError
    end
  end

  model = data_model.at_xpath('model')

  @name = model['name']
  @version = model['systemVersion']
  @entities = model.xpath('entity').collect { |element| Entity.new(element) }
end

Instance Attribute Details

#entitiesObject (readonly)

Returns the value of attribute entities.



7
8
9
# File 'lib/core_data/data_model.rb', line 7

def entities
  @entities
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/core_data/data_model.rb', line 7

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/core_data/data_model.rb', line 7

def version
  @version
end