Class: PlanMyStuff::Repo
- Inherits:
-
Object
- Object
- PlanMyStuff::Repo
- Defined in:
- lib/plan_my_stuff/repo.rb
Instance Attribute Summary collapse
-
#key ⇒ Symbol?
readonly
Configured key (e.g. :my_repo).
-
#name ⇒ String
readonly
Repo name (e.g. “MyRepository”).
-
#organization ⇒ String
readonly
Organization name (e.g. “YourOrgName”).
Class Method Summary collapse
-
.resolve(repo = nil) ⇒ PlanMyStuff::Repo
Builds a Repo instance from a Symbol key, full name String, or nil (default).
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares by full_name.
-
#full_name ⇒ String
(also: #to_s, #to_str)
Full repo path (e.g. “YourOrgName/MyRepository”).
-
#initialize(name:, organization:, key: nil) ⇒ Repo
constructor
A new instance of Repo.
Constructor Details
#initialize(name:, organization:, key: nil) ⇒ Repo
Returns a new instance of Repo.
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
#key ⇒ Symbol? (readonly)
Returns configured key (e.g. :my_repo).
6 7 8 |
# File 'lib/plan_my_stuff/repo.rb', line 6 def key @key end |
#name ⇒ String (readonly)
Returns repo name (e.g. “MyRepository”).
9 10 11 |
# File 'lib/plan_my_stuff/repo.rb', line 9 def name @name end |
#organization ⇒ String (readonly)
Returns 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).
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.
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_name ⇒ String Also known as: to_s, to_str
Returns 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 |