Class: LicenseFinder::YmlToSql
- Inherits:
-
Object
- Object
- LicenseFinder::YmlToSql
- Defined in:
- lib/license_finder/yml_to_sql.rb
Defined Under Namespace
Modules: Sql
Instance Attribute Summary collapse
-
#legacy_attrs ⇒ Object
readonly
Returns the value of attribute legacy_attrs.
Class Method Summary collapse
- .convert_all(all_legacy_attrs) ⇒ Object
- .convert_if_required ⇒ Object
- .load_yml ⇒ Object
- .needs_conversion? ⇒ Boolean
- .remove_yml ⇒ Object
- .yml_path ⇒ Object
Instance Method Summary collapse
- #associate_bundler_groups ⇒ Object
- #associate_children ⇒ Object
- #convert ⇒ Object
- #create_approval ⇒ Object
- #create_dependency ⇒ Object
- #create_license ⇒ Object
- #find_bundler_groups ⇒ Object
- #find_children ⇒ Object
-
#initialize(attrs) ⇒ YmlToSql
constructor
A new instance of YmlToSql.
- #non_bundler_source? ⇒ Boolean
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_attrs ⇒ Object (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_required ⇒ Object
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_yml ⇒ Object
10 11 12 |
# File 'lib/license_finder/yml_to_sql.rb', line 10 def self.load_yml YAML.load File.read(yml_path) end |
.needs_conversion? ⇒ Boolean
22 23 24 |
# File 'lib/license_finder/yml_to_sql.rb', line 22 def self.needs_conversion? File.exists?(yml_path) end |
.remove_yml ⇒ Object
26 27 28 |
# File 'lib/license_finder/yml_to_sql.rb', line 26 def self.remove_yml File.delete(yml_path) end |
.yml_path ⇒ Object
30 31 32 |
# File 'lib/license_finder/yml_to_sql.rb', line 30 def self.yml_path LicenseFinder.config.dependencies_yaml end |
Instance Method Details
#associate_bundler_groups ⇒ Object
55 56 57 58 59 |
# File 'lib/license_finder/yml_to_sql.rb', line 55 def associate_bundler_groups find_bundler_groups.each do |group| @dep.add_bundler_group(group) end end |
#associate_children ⇒ Object
49 50 51 52 53 |
# File 'lib/license_finder/yml_to_sql.rb', line 49 def associate_children find_children.each do |child| @dep.add_child(child) end end |
#convert ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/license_finder/yml_to_sql.rb', line 40 def convert @dep = create_dependency @dep.license = create_license @dep.approval = create_approval @dep.manual = non_bundler_source? associate_bundler_groups @dep.save end |
#create_approval ⇒ Object
73 74 75 |
# File 'lib/license_finder/yml_to_sql.rb', line 73 def create_approval Sql::Approval.convert(legacy_attrs) end |
#create_dependency ⇒ Object
65 66 67 |
# File 'lib/license_finder/yml_to_sql.rb', line 65 def create_dependency Sql::Dependency.convert(legacy_attrs) end |
#create_license ⇒ Object
69 70 71 |
# File 'lib/license_finder/yml_to_sql.rb', line 69 def create_license LicenseAlias.find_or_create(name: legacy_attrs['license']) end |
#find_bundler_groups ⇒ Object
81 82 83 84 85 |
# File 'lib/license_finder/yml_to_sql.rb', line 81 def find_bundler_groups (legacy_attrs['bundler_groups'] || []).map do |name| Sql::BundlerGroup.find_or_create(name: name.to_s) end end |
#find_children ⇒ Object
77 78 79 |
# File 'lib/license_finder/yml_to_sql.rb', line 77 def find_children Sql::Dependency.where(name: legacy_attrs['children']) end |
#non_bundler_source? ⇒ Boolean
61 62 63 |
# File 'lib/license_finder/yml_to_sql.rb', line 61 def non_bundler_source? @legacy_attrs['source'] == "bundle" ? false : true end |