Class: EAD

Inherits:
Object
  • Object
show all
Defined in:
lib/ead.rb

Instance Method Summary collapse

Instance Method Details

#check_implement_objectsObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ead.rb', line 51

def check_implement_objects
  Table.all.each(&:create_model)

  Table.all.each(&:add_polymorphic_reference_migration_for_sti)

  Table.all.each(&:add_reference_migration)

  Association.all.each(&:set_middle_entity)

  Association.all.each(&:update_model_from_entity)
end

#check_latest_versionObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ead.rb', line 63

def check_latest_version
  response = JSON.parse RestClient.get 'https://api.github.com/repos/ozovalihasan/ead/tags'

  unless response.first['name'] == 'v0.4.6'
    puts "\n\n----------------"
    puts "\n\e[33m#{
      'A new version of this gem has been released. '\
        'Please check it. https://github.com/ozovalihasan/ead-g/releases'
    }\e[0m"

    puts "\n----------------\n\n"
  end
rescue StandardError
  puts "\n\n----------------"
  puts "\n\e[31m#{
    'If you want to check the latest version of this gem, '\
      'you need to have a stable internet connection.'
  }\e[0m"

  puts "\n----------------\n\n"
end

#create_objects(file) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ead.rb', line 29

def create_objects(file)
  parsed_file = JSON.parse(file)

  parsed_tables = parsed_file['tables']
  parsed_nodes = parsed_file['nodes']
  parsed_edges = parsed_file['edges']

  @tables = parsed_tables.map do |id, parsed_table|
    Table.new(id, parsed_table)
  end

  Table.update_superclasses(parsed_tables)

  @nodes = parsed_nodes.map do |node|
    Entity.new(node)
  end

  @edges = parsed_edges.map do |edge|
    Association.new(edge)
  end
end

#import_JSON(user_arguments) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ead.rb', line 7

def import_JSON(user_arguments)
  file = File.read(user_arguments[0] || './EAD.json')

  unless ['0.4.0', '0.4.1', '0.4.2', '0.4.3', '0.4.4', '0.4.5', '0.4.6'].include? JSON.parse(file)['version']
    puts "\n\n----------------"
    puts "\e[31m#{
      'Versions of your EAD file and the gem are not compatible. '\
        'So, you may have some unexpected results.'\
        'To run your EAD file correctly, please run'
    }\e[0m"

    puts "\e[31m#{
      "\ngem install ead -v #{JSON.parse(file)['version']}"
    }\e[0m"
    puts "----------------\n\n"

    raise StandardError, msg = 'Incompatible version'
  end

  file
end

#start(user_arguments) ⇒ Object



85
86
87
88
89
90
# File 'lib/ead.rb', line 85

def start(user_arguments)
  check_latest_version
  file = import_JSON(user_arguments)
  create_objects(file)
  check_implement_objects
end