Class: LicenseFinder::YmlToSql

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

Defined Under Namespace

Modules: Sql

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ YmlToSql

Returns a new instance of YmlToSql.



34
35
36
# File 'lib/license_finder/yml_to_sql.rb', line 34

def initialize(attrs)
  @legacy_attrs = attrs
end

Instance Attribute Details

#legacy_attrsObject (readonly)

Returns the value of attribute legacy_attrs.



38
39
40
# File 'lib/license_finder/yml_to_sql.rb', line 38

def legacy_attrs
  @legacy_attrs
end

Class Method Details

.convert_all(all_legacy_attrs) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/license_finder/yml_to_sql.rb', line 14

def self.convert_all(all_legacy_attrs)
  converters = all_legacy_attrs.map do |attrs|
    new(attrs)
  end
  converters.each(&:convert)
  converters.each(&:associate_children)
end

.convert_if_requiredObject



3
4
5
6
7
8
# File 'lib/license_finder/yml_to_sql.rb', line 3

def self.convert_if_required
  if needs_conversion?
    convert_all(load_yml)
    remove_yml
  end
end

.load_ymlObject



10
11
12
# File 'lib/license_finder/yml_to_sql.rb', line 10

def self.load_yml
  YAML.load yml_path.read
end

.needs_conversion?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/license_finder/yml_to_sql.rb', line 22

def self.needs_conversion?
  yml_path.exist?
end

.remove_ymlObject



26
27
28
# File 'lib/license_finder/yml_to_sql.rb', line 26

def self.remove_yml
  yml_path.delete
end

.yml_pathObject



30
31
32
# File 'lib/license_finder/yml_to_sql.rb', line 30

def self.yml_path
  LicenseFinder.config.artifacts.legacy_yaml_file
end

Instance Method Details

#add_approvalObject



64
65
66
# File 'lib/license_finder/yml_to_sql.rb', line 64

def add_approval
  @dep.manual_approval = Sql::ManualApproval.new if legacy_attrs['approved']
end

#associate_bundler_groupsObject



54
55
56
57
58
# File 'lib/license_finder/yml_to_sql.rb', line 54

def associate_bundler_groups
  find_bundler_groups.each do |group|
    @dep.add_bundler_group(group)
  end
end

#associate_childrenObject



48
49
50
51
52
# File 'lib/license_finder/yml_to_sql.rb', line 48

def associate_children
  find_children.each do |child|
    @dep.add_child(child)
  end
end

#convertObject



40
41
42
43
44
45
46
# File 'lib/license_finder/yml_to_sql.rb', line 40

def convert
  @dep = create_dependency
  @dep.added_manually = manually_managed?
  add_approval
  associate_bundler_groups
  @dep.save
end

#create_dependencyObject



68
69
70
# File 'lib/license_finder/yml_to_sql.rb', line 68

def create_dependency
  Sql::Dependency.convert(legacy_attrs)
end

#find_bundler_groupsObject



76
77
78
79
80
# File 'lib/license_finder/yml_to_sql.rb', line 76

def find_bundler_groups
  (legacy_attrs['bundler_groups'] || []).map do |name|
    Sql::BundlerGroup.find_or_create(name: name.to_s)
  end
end

#find_childrenObject



72
73
74
# File 'lib/license_finder/yml_to_sql.rb', line 72

def find_children
  Sql::Dependency.where(name: legacy_attrs['children'])
end

#manually_managed?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/license_finder/yml_to_sql.rb', line 60

def manually_managed?
  legacy_attrs['source'] != "bundle"
end