Class: Flutter::Pub::Spec
- Inherits:
-
Object
- Object
- Flutter::Pub::Spec
- Defined in:
- lib/cocoapods-embed-flutter/flutter/pubspec.rb
Overview
The Specification provides a DSL to describe a flutter project. A project is defined as a library originating from a source. A specification can support detailed attributes for modules of code through dependencies.
Usually it is stored in ‘pubspec.yaml` file.
Instance Attribute Summary collapse
-
#defined_in_file ⇒ String
readonly
The path where the specification is defined, if loaded from a file.
Class Method Summary collapse
-
.find(name, path) ⇒ Spec
Returns the path to ‘pubspec` with the given name and location to search.
-
.find_file(name, path) ⇒ String
Returns the path to ‘pubspec` with the given name and location to search.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
See if two Spec instances refer to the same pubspecs.
-
#all_dependencies ⇒ Array<Dependency>
The list of all the projects this specification depends upon.
-
#dependencies ⇒ Array<Dependency>
The list of all the projects this specification depends upon and are included in app release.
-
#dev_dependencies ⇒ Array<Dependency>
The list of all the projects this specification depends upon only during development.
-
#hash ⇒ Fixnum
A hash identical for equals objects.
-
#initialize(path) ⇒ Spec
constructor
A new instance of Spec.
-
#method_missing(m, *args, &block) ⇒ Object
Allows accessing top level values in ‘pubspec.yaml`, i.e.
-
#module? ⇒ Boolean
If this specification is a module specification.
-
#package_cache_path ⇒ String
The path to the flutter project dependencies cache file.
-
#pod_helper_path ⇒ String
The path to the flutter project.
-
#project_path ⇒ String
The path to the flutter project.
-
#pub_get ⇒ Concurrent::Promises::Future, Nil
Runs ‘flutter pub get` on project directory concurrently.
Constructor Details
#initialize(path) ⇒ Spec
Returns a new instance of Spec.
25 26 27 28 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 25 def initialize(path) @data = YAML.load_file path @defined_in_file = path end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
Allows accessing top level values in ‘pubspec.yaml`, i.e. name, description, version etc.
179 180 181 182 183 184 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 179 def method_missing(m, *args, &block) if @data.include?(m.to_s) return @data[m.to_s] end super.method_missing(m, *args, &block) end |
Instance Attribute Details
#defined_in_file ⇒ String (readonly)
Returns the path where the specification is defined, if loaded from a file.
20 21 22 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 20 def defined_in_file @defined_in_file end |
Class Method Details
.find(name, path) ⇒ Spec
either the flutter module or the ‘pubspec` of the flutter module can be in the path. Optionally you can provide the `pubspec` file directly.
Returns the path to ‘pubspec` with the given name and location to search.
73 74 75 76 77 78 79 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 73 def self.find(name, path) pubspec_path = find_file(name, path) raise StandardError, "Invalid path: '#{path}' for flutter module: '#{name}'." unless pubspec_path pubspec = Spec.new(pubspec_path) raise StandardError, "Invalid path: '#{path}' for flutter module: '#{name}'." unless pubspec.name == name return pubspec end |
.find_file(name, path) ⇒ String
either the flutter module or the ‘pubspec` of the flutter module can be in the path. Optionally you can provide the `pubspec` file directly.
Returns the path to ‘pubspec` with the given name and location to search.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 44 def self.find_file(name, path) path = File.(path, Dir.pwd) if File.basename(path) == Pub::SPEC_FILE return path elsif Dir.exists?(File.(name, path)) && File.exists?(File.(Pub::SPEC_FILE, File.(name, path))) return File.(Pub::SPEC_FILE, File.(name, path)) elsif File.exists?(File.(Pub::SPEC_FILE, path)) return File.(Pub::SPEC_FILE, path) else return nil end end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
See if two Flutter::Pub::Spec instances refer to the same pubspecs.
153 154 155 156 157 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 153 def ==(other) self.class === other && other.defined_in_file == defined_in_file && other.instance_variable_get(:@data) == @data end |
#all_dependencies ⇒ Array<Dependency>
Returns the list of all the projects this specification depends upon.
126 127 128 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 126 def all_dependencies dependencies + dev_dependencies end |
#dependencies ⇒ Array<Dependency>
Returns the list of all the projects this specification depends upon and are included in app release.
110 111 112 113 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 110 def dependencies return [] unless @data.include?('dependencies') Dependency.create_from_hash(@data['dependencies'], self) end |
#dev_dependencies ⇒ Array<Dependency>
Returns the list of all the projects this specification depends upon only during development.
118 119 120 121 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 118 def dev_dependencies return [] unless @data.include?('dev_dependencies') Dependency.create_from_hash(@data['dev_dependencies'], self) end |
#hash ⇒ Fixnum
Returns A hash identical for equals objects.
161 162 163 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 161 def hash [defined_in_file, @data].hash end |
#module? ⇒ Boolean
Returns If this specification is a module specification.
83 84 85 86 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 83 def module? return false unless @data.include?(Flutter::NAME) return @data[Flutter::NAME].is_a?(Hash) && @data[Flutter::NAME].include?('module') end |
#package_cache_path ⇒ String
Returns the path to the flutter project dependencies cache file.
97 98 99 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 97 def package_cache_path File.join(project_path, Pub::TOOL_DIR, Pub::CACHE_FILE) end |
#pod_helper_path ⇒ String
Returns the path to the flutter project.
103 104 105 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 103 def pod_helper_path File.join(project_path, '.ios', Flutter::DIR_NAME, 'podhelper.rb') if module? end |
#project_path ⇒ String
Returns the path to the flutter project.
90 91 92 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 90 def project_path File.dirname(defined_in_file) end |
#pub_get ⇒ Concurrent::Promises::Future, Nil
Runs ‘flutter pub get` on project directory concurrently.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cocoapods-embed-flutter/flutter/pubspec.rb', line 137 def pub_get future = @@current_pubgets[self] return nil if !future.nil? future = Concurrent::Promises.future do stdout, stderr, status = Open3.capture3('flutter pub get', :chdir => self.project_path) :result end @@current_pubgets[self] = future return Concurrent::Promises.zip(future, *all_dependencies.map(&:install).compact) end |