Class: FlutterRb::PubspecParser

Inherits:
Object
  • Object
show all
Defined in:
lib/flutter_rb/project/specs/flutter/pubspec.rb

Overview

This class is responsible for parsing a pubspec.yaml file and creating a Pubspec object.

Instance Method Summary collapse

Constructor Details

#initialize(path, pubspec) ⇒ PubspecParser

Initializes a new instance of PubspecParser.

Parameters:

  • path (String)

    The path to the pubspec.yaml file.

  • pubspec (Hash)

    The parsed pubspec.yaml file as a Hash.



50
51
52
53
# File 'lib/flutter_rb/project/specs/flutter/pubspec.rb', line 50

def initialize(path, pubspec)
  @path = path
  @pubspec = pubspec
end

Instance Method Details

#dev_dependencies(pubspec) ⇒ Array<DevDependency>

Parses the pubspec.yaml file and extracts the dev dependencies.

Parameters:

  • pubspec (Hash)

    The parsed pubspec.yaml file as a Hash.

Returns:

  • (Array<DevDependency>)

    An array of parsed DevDependency objects.



85
86
87
88
89
90
91
92
# File 'lib/flutter_rb/project/specs/flutter/pubspec.rb', line 85

def dev_dependencies(pubspec)
  pubspec['dev_dependencies']&.map do |dev_dependency|
    DevDependency.new(
      dev_dependency.first,
      dev_dependency.last
    )
  end
end

#parsePubspec

Parses the pubspec.yaml file and creates a Pubspec object.

Returns:

  • (Pubspec)

    The parsed Pubspec object.



58
59
60
61
62
63
64
65
# File 'lib/flutter_rb/project/specs/flutter/pubspec.rb', line 58

def parse
  Pubspec.new(
    @path,
    pubspec_info(@pubspec),
    dev_dependencies(@pubspec),
    platform_plugins(@pubspec)
  )
end

#platform_plugins(pubspec) ⇒ Array<PlatformPlugin>

Parses the pubspec.yaml file and extracts the platform plugins.

Parameters:

  • pubspec (Hash)

    The parsed pubspec.yaml file as a Hash.

Returns:

  • (Array<PlatformPlugin>)

    An array of parsed PlatformPlugin objects.



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/flutter_rb/project/specs/flutter/pubspec.rb', line 98

def platform_plugins(pubspec)
  pubspec.dig('flutter', 'plugin', 'platforms')&.map do |platform_plugin|
    plugin_info = platform_plugin.last

    PlatformPlugin.new(
      plugin_info['package'],
      plugin_info['pluginClass'],
      platform_plugin.first == Platform::ANDROID ? Platform::ANDROID : Platform::IOS
    )
  end
end

#pubspec_info(pubspec) ⇒ PubspecInfo

Parses the pubspec.yaml file and extracts the general information.

Parameters:

  • pubspec (Hash)

    The parsed pubspec.yaml file as a Hash.

Returns:



71
72
73
74
75
76
77
78
79
# File 'lib/flutter_rb/project/specs/flutter/pubspec.rb', line 71

def pubspec_info(pubspec)
  PubspecInfo.new(
    pubspec['name'],
    pubspec['description'],
    pubspec['version'],
    pubspec['author'],
    pubspec['homepage']
  )
end