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)


70
71
72
73
74
# File 'lib/plan_my_stuff/repo.rb', line 70

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:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/plan_my_stuff/repo.rb', line 23

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
    key = PlanMyStuff.configuration.repos.key(repo)
    from_full_name(repo, key: key)
  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)


96
97
98
99
100
101
102
103
104
105
# File 'lib/plan_my_stuff/repo.rb', line 96

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”)



77
78
79
# File 'lib/plan_my_stuff/repo.rb', line 77

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