Class: PlanMyStuff::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/plan_my_stuff/repo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, organization:, key: nil) ⇒ Repo

Returns a new instance of Repo.

Parameters:

  • name (String)
  • organization (String)
  • key (Symbol, nil) (defaults to: nil)


80
81
82
83
84
# File 'lib/plan_my_stuff/repo.rb', line 80

def initialize(name:, organization:, key: nil)
  @key = key
  @name = name
  @organization = organization
end

Instance Attribute Details

#keySymbol? (readonly)

Returns configured key (e.g. :my_repo).

Returns:

  • (Symbol, nil)

    configured key (e.g. :my_repo)



6
7
8
# File 'lib/plan_my_stuff/repo.rb', line 6

def key
  @key
end

#nameString (readonly)

Returns repo name (e.g. “MyRepository”).

Returns:

  • (String)

    repo name (e.g. “MyRepository”)



9
10
11
# File 'lib/plan_my_stuff/repo.rb', line 9

def name
  @name
end

#organizationString (readonly)

Returns organization name (e.g. “YourOrgName”).

Returns:

  • (String)

    organization name (e.g. “YourOrgName”)



12
13
14
# File 'lib/plan_my_stuff/repo.rb', line 12

def organization
  @organization
end

Class Method Details

.resolve!(repo = nil) ⇒ PlanMyStuff::Repo

Builds a Repo instance from a Symbol key, full name String, or nil (default).

Parameters:

Returns:

Raises:

  • (PlanMyStuff::ConfigurationError)

    if repo is not provided and cannot be resolved from config

  • (ArgumentError)

    if repo cannot be resolved

  • (ArgumentError)

    if repo is invalid format



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/plan_my_stuff/repo.rb', line 27

def resolve!(repo = nil)
  return repo if repo.is_a?(PlanMyStuff::Repo)

  repo ||= PlanMyStuff.configuration.default_repo

  if repo.nil?
    raise(
      PlanMyStuff::ConfigurationError,
      'No repo provided and config.default_repo is not set. ' \
        'Either pass repo: explicitly or set config.default_repo in your initializer.',
    )
  end

  case repo
  when Symbol
    full_name = PlanMyStuff.configuration.repos[repo]
    raise(ArgumentError, "Unknown repo key: #{repo.inspect}") if full_name.nil?

    from_full_name!(full_name, key: repo)
  when String
    if PlanMyStuff.configuration.repos.has_key?(repo.to_sym)
      resolve!(repo.to_sym)
    else
      key = PlanMyStuff.configuration.repos.key(repo)
      from_full_name!(repo, key: key)
    end
  else
    raise(ArgumentError, "Cannot resolve repo: #{repo.inspect}")
  end
end

Instance Method Details

#==(other) ⇒ Boolean

Compares by full_name. Accepts another Repo or a String.

Parameters:

Returns:

  • (Boolean)


106
107
108
109
110
111
112
113
114
115
# File 'lib/plan_my_stuff/repo.rb', line 106

def ==(other)
  case other
  when PlanMyStuff::Repo
    full_name == other.full_name
  when String
    full_name == other
  else
    super
  end
end

#full_nameString Also known as: to_s, to_str

Returns full repo path (e.g. “YourOrgName/MyRepository”).

Returns:

  • (String)

    full repo path (e.g. “YourOrgName/MyRepository”)



87
88
89
# File 'lib/plan_my_stuff/repo.rb', line 87

def full_name
  "#{organization}/#{name}"
end