Class: Rack::CoreData::DataModel

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/core-data/data_model.rb,
lib/rack/core-data/data_model/entity.rb,
lib/rack/core-data/data_model/attribute.rb,
lib/rack/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.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rack/core-data/data_model.rb', line 7

def initialize(data_model)
  loop do
    case data_model
    when File, /^\<\?xml/
      data_model = ::Nokogiri::XML(data_model) and redo
    when String
      case data_model
      when /\.xcdatamodeld?$/
        data_model = Dir[File.join(data_model, "/**/contents")].first and redo
      else
        data_model = ::File.read(data_model) and 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.



5
6
7
# File 'lib/rack/core-data/data_model.rb', line 5

def entities
  @entities
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rack/core-data/data_model.rb', line 5

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/rack/core-data/data_model.rb', line 5

def version
  @version
end