Skip to content

Commit 4ddd83b

Browse files
committed
chore: reorganize modules
1 parent aa9955c commit 4ddd83b

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

lib/cocoapods-embed-flutter.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
require 'cocoapods-embed-flutter/gem_version'
22
require 'cocoapods-embed-flutter/source'
3-
4-
include CocoapodsEmbedFlutter::FlutterModule
3+
require 'cocoapods-embed-flutter/hooks'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'cocoapods-embed-flutter/hooks/post_install'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module CocoapodsEmbedFlutter
2+
# Registers for CocoaPods plugin hooks
3+
module Hooks
4+
Pod::HooksManager.register(CocoapodsEmbedFlutter::NAME, :post_install) do |installer, options|
5+
# Do nothing
6+
end
7+
end
8+
end
Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,41 @@
11
require 'cocoapods-embed-flutter/gem_version'
22
require 'cocoapods-embed-flutter/flutter/pubspec'
33

4-
module CocoapodsEmbedFlutter
5-
module FlutterModule
6-
def flutter_module(name = nil, *requirements)
7-
raise StandardError, 'A flutter module requires a name.' unless name
4+
module Pod
5+
class Podfile
6+
module DSL
7+
def flutter_module(name = nil, *requirements)
8+
raise StandardError, 'A flutter module requires a name.' unless name
89

9-
options = requirements.last
10-
raise StandardError, "No options for flutter module: '#{name}'." unless options.is_a?(Hash)
10+
options = requirements.last
11+
raise StandardError, "No options for flutter module: '#{name}'." unless options.is_a?(Hash)
1112

12-
path = options[:path]
13-
raise StandardError, "No path for flutter module: '#{name}'." unless path
13+
path = options[:path]
14+
raise StandardError, "No path for flutter module: '#{name}'." unless path
1415

15-
path = File.expand_path(path, Dir.pwd)
16-
if File.basename(path) == Flutter::PUBSPEC_FILENAME
17-
pubspec = Flutter::PubSpec.new(path)
18-
raise StandardError, "Invalid pubspec path: '#{path}' for flutter module: '#{name}'." unless pubspec.name == name
19-
path = File.dirname(path)
20-
elsif Dir.exists?(File.expand_path(name, path)) && File.exists?(File.expand_path(Flutter::PUBSPEC_FILENAME, File.expand_path(name, path)))
21-
module_path = File.expand_path(name, path)
22-
pubspec = Flutter::PubSpec.new(File.expand_path(Flutter::PUBSPEC_FILENAME, module_path))
23-
raise StandardError, "Invalid path: '#{path}' for flutter module: '#{name}'." unless pubspec.name == name
24-
path = module_path
25-
elsif File.exists?(File.expand_path(Flutter::PUBSPEC_FILENAME, path))
26-
pubspec = Flutter::PubSpec.new(File.expand_path(Flutter::PUBSPEC_FILENAME, path))
27-
raise StandardError, "Invalid path: '#{path}' for flutter module: '#{name}'." unless pubspec.name == name
28-
else
29-
raise StandardError, "Invalid path: '#{path}' for flutter module: '#{name}'."
30-
end
16+
path = File.expand_path(path, Dir.pwd)
17+
if File.basename(path) == Flutter::PUBSPEC_FILENAME
18+
pubspec = Flutter::PubSpec.new(path)
19+
raise StandardError, "Invalid pubspec path: '#{path}' for flutter module: '#{name}'." unless pubspec.name == name
20+
path = File.dirname(path)
21+
elsif Dir.exists?(File.expand_path(name, path)) && File.exists?(File.expand_path(Flutter::PUBSPEC_FILENAME, File.expand_path(name, path)))
22+
module_path = File.expand_path(name, path)
23+
pubspec = Flutter::PubSpec.new(File.expand_path(Flutter::PUBSPEC_FILENAME, module_path))
24+
raise StandardError, "Invalid path: '#{path}' for flutter module: '#{name}'." unless pubspec.name == name
25+
path = module_path
26+
elsif File.exists?(File.expand_path(Flutter::PUBSPEC_FILENAME, path))
27+
pubspec = Flutter::PubSpec.new(File.expand_path(Flutter::PUBSPEC_FILENAME, path))
28+
raise StandardError, "Invalid path: '#{path}' for flutter module: '#{name}'." unless pubspec.name == name
29+
else
30+
raise StandardError, "Invalid path: '#{path}' for flutter module: '#{name}'."
31+
end
3132

32-
pubspec.setup
33-
raise StandardError, "Invalid flutter module: '#{name}'." unless File.exists?(pubspec.pod_helper_path)
33+
pubspec.setup
34+
raise StandardError, "Invalid flutter module: '#{name}'." unless File.exists?(pubspec.pod_helper_path)
3435

35-
load pubspec.pod_helper_path
36-
install_all_flutter_pods(path)
37-
end
38-
end
39-
40-
# Registers for CocoaPods plugin hooks
41-
module Hooks
42-
Pod::HooksManager.register(CocoapodsEmbedFlutter::NAME, :post_install) do |installer, options|
43-
# Do nothing
36+
load pubspec.pod_helper_path
37+
install_all_flutter_pods(path)
38+
end
4439
end
4540
end
4641
end

0 commit comments

Comments
 (0)