Class: Flutter::Pub::Dependency

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-embed-flutter/flutter/dependency.rb

Overview

Provides a DSL to describe a flutter dependency. A dependency is defined in ‘pubspec.yaml` in `dependencies` or `dev_dependencies` sections.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, requirements, parent_spec, dev_dependency = false) ⇒ Dependency

Returns a new instance of Dependency.

Parameters:

  • name (String)

    the name of the specification.

  • requirements (String, Hash)

    the requirements for dependency as declred in ‘pubspec`

  • parent_spec (Spec)

    the parent specification where dependency declared

  • dev_dependency (Boolean) (defaults to: false)

    Whether the dependency only required during development

Raises:

  • (StandardError)


36
37
38
39
40
41
42
43
# File 'lib/cocoapods-embed-flutter/flutter/dependency.rb', line 36

def initialize(name, requirements, parent_spec, dev_dependency = false)
  raise StandardError, 'A flutter dependency requires a name.' unless name
  raise StandardError, 'A flutter dependency requires a parent pubspec.' unless parent_spec.is_a?(Flutter::Pub::Spec)
  @name = name
  @requirements = requirements
  @parent_spec = parent_spec
  @is_dev_dependency = dev_dependency
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 dependency requirements, if #requirements type is Hash, i.e. path, git etc.

Parameters:

  • m (Symbol)

    top level key value to access, i.e. path, git etc.

Returns:

Raises:

  • (NoMethodError)

    if no method or custom attribute exists by the attribute name in #requirements or #requirements is not a Hash.



100
101
102
103
104
105
# File 'lib/cocoapods-embed-flutter/flutter/dependency.rb', line 100

def method_missing(m, *args, &block)
  if requirements.is_a?(Hash) && requirements.include?(m.to_s)
    return requirements[m.to_s]
  end
  super.method_missing(m, *args, &block)
end

Instance Attribute Details

#is_dev_dependencyBoolean (readonly)

Returns If this specification is an app specification.

Returns:

  • (Boolean)

    If this specification is an app specification.



22
23
24
# File 'lib/cocoapods-embed-flutter/flutter/dependency.rb', line 22

def is_dev_dependency
  @is_dev_dependency
end

#nameString (readonly)

Returns the name of the dependency.

Returns:

  • (String)

    the name of the dependency.



11
12
13
# File 'lib/cocoapods-embed-flutter/flutter/dependency.rb', line 11

def name
  @name
end

#parent_specSpec (readonly)

Returns the parent specification where dependency declared.

Returns:

  • (Spec)

    the parent specification where dependency declared.



19
20
21
# File 'lib/cocoapods-embed-flutter/flutter/dependency.rb', line 19

def parent_spec
  @parent_spec
end

#requirementsString, Hash (readonly)

Returns the requirements for dependency as declred in parent ‘pubspec`.

Returns:

  • (String, Hash)

    the requirements for dependency as declred in parent ‘pubspec`.



15
16
17
# File 'lib/cocoapods-embed-flutter/flutter/dependency.rb', line 15

def requirements
  @requirements
end

Class Method Details

.create_from_hash(hash, parent_spec, dev_dependency = false) ⇒ Array<Dependency>

Returns dependencies from hash declared in ‘dependencies` or `dev_dependencies` section in `pubspec.yaml` file.

Parameters:

  • hash (Hash)

    declared in ‘dependencies` or `dev_dependencies` section in `pubspec.yaml` file

  • parent_spec (Spec)

    the parent specification where dependency declared

  • dev_dependency (Boolean) (defaults to: false)

    Whether the dependency only required during development

Returns:

  • (Array<Dependency>)

    dependencies from hash declared in ‘dependencies` or `dev_dependencies` section in `pubspec.yaml` file.

Raises:

  • (StandardError)


60
61
62
63
# File 'lib/cocoapods-embed-flutter/flutter/dependency.rb', line 60

def self.create_from_hash(hash, parent_spec, dev_dependency = false)
  raise StandardError, 'A flutter dependency requires a parent pubspec.' unless parent_spec.is_a?(Flutter::Pub::Spec)
  hash.keys.map { |key| Dependency.new(key, hash[key], parent_spec, dev_dependency) }
end

Instance Method Details

#installConcurrent::Promises::Future, Nil

Concurrently install this dependency for the parent project.

Returns:

  • (Concurrent::Promises::Future, Nil)

    Nil if not a local dependency, otherwise returns future for #spec‘s pub_get task.



83
84
85
# File 'lib/cocoapods-embed-flutter/flutter/dependency.rb', line 83

def install
  spec.pub_get if local?
end

#local?Boolean

Returns If this dependency is a local flutter project.

Returns:

  • (Boolean)

    If this dependency is a local flutter project.



67
68
69
# File 'lib/cocoapods-embed-flutter/flutter/dependency.rb', line 67

def local?
  requirements.is_a?(Hash) && requirements.include?('path')
end

#specSpec

Returns for this dependency if this dependency is a local flutter project.

Returns:

  • (Spec)

    for this dependency if this dependency is a local flutter project.



73
74
75
# File 'lib/cocoapods-embed-flutter/flutter/dependency.rb', line 73

def spec
  Spec.find(name, File.expand_path(path, File.dirname(parent_spec.defined_in_file)))
end