Class: Gembrew::Config
- Inherits:
-
Object
- Object
- Gembrew::Config
- Defined in:
- lib/gembrew/config.rb
Defined Under Namespace
Classes: Dependency
Constant Summary collapse
- DEPENDENCY_TAGS =
%w[:system_on_macos].freeze
- DIRECTORY =
'gembrew'- ALLOWED_KEYS =
%w[ gem version source output desc homepage license executable dependencies test test_from_file ].freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#project_path ⇒ Object
readonly
Returns the value of attribute project_path.
Class Method Summary collapse
- .all(project_path = Pathname.pwd) ⇒ Object
- .find(name, project_path = Pathname.pwd) ⇒ Object
- .validate_name!(name) ⇒ Object
Instance Method Summary collapse
- #dependencies ⇒ Object
- #description ⇒ Object
- #executable ⇒ Object
- #gem_name ⇒ Object
- #homepage ⇒ Object
-
#initialize(path, project_path: nil) ⇒ Config
constructor
A new instance of Config.
- #license ⇒ Object
- #name ⇒ Object
- #output_path ⇒ Object
- #source ⇒ Object
- #source_gemspec ⇒ Object
- #source_repo ⇒ Object
- #source_tag ⇒ Object
- #source_type ⇒ Object
- #test_body ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(path, project_path: nil) ⇒ Config
Returns a new instance of Config.
39 40 41 42 43 44 |
# File 'lib/gembrew/config.rb', line 39 def initialize(path, project_path: nil) @path = Pathname(path). @project_path = project_path ? Pathname(project_path). : @path.dirname.parent @data = load_data validate end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
17 18 19 |
# File 'lib/gembrew/config.rb', line 17 def path @path end |
#project_path ⇒ Object (readonly)
Returns the value of attribute project_path.
17 18 19 |
# File 'lib/gembrew/config.rb', line 17 def project_path @project_path end |
Class Method Details
.all(project_path = Pathname.pwd) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/gembrew/config.rb', line 19 def self.all(project_path = Pathname.pwd) project_path = Pathname(project_path). paths = (project_path/DIRECTORY).glob('*.yml').sort raise Error, "No gem configurations found in #{project_path/DIRECTORY}" if paths.empty? paths.map { |path| new path, project_path: project_path } end |
.find(name, project_path = Pathname.pwd) ⇒ Object
27 28 29 30 31 |
# File 'lib/gembrew/config.rb', line 27 def self.find(name, project_path = Pathname.pwd) validate_name! name project_path = Pathname(project_path). new project_path/DIRECTORY/"#{name}.yml", project_path: project_path end |
.validate_name!(name) ⇒ Object
33 34 35 36 37 |
# File 'lib/gembrew/config.rb', line 33 def self.validate_name!(name) return name if name&.match?(/\A[a-zA-Z0-9._-]+\z/) raise Error, "Invalid gem name: #{name.inspect}" end |
Instance Method Details
#dependencies ⇒ Object
60 61 62 |
# File 'lib/gembrew/config.rb', line 60 def dependencies @dependencies ||= data.fetch('dependencies', []).map { |value| parse_dependency value } end |
#description ⇒ Object
55 |
# File 'lib/gembrew/config.rb', line 55 def description = data['desc'] |
#executable ⇒ Object
58 |
# File 'lib/gembrew/config.rb', line 58 def executable = data['executable'] |
#gem_name ⇒ Object
47 |
# File 'lib/gembrew/config.rb', line 47 def gem_name = data.fetch('gem').to_s |
#homepage ⇒ Object
56 |
# File 'lib/gembrew/config.rb', line 56 def homepage = data['homepage'] |
#license ⇒ Object
57 |
# File 'lib/gembrew/config.rb', line 57 def license = data['license'] |
#name ⇒ Object
46 |
# File 'lib/gembrew/config.rb', line 46 def name = path.basename('.yml').to_s |
#output_path ⇒ Object
54 |
# File 'lib/gembrew/config.rb', line 54 def output_path = (project_path/(data['output'] || "Formula/#{name}.rb")). |
#source ⇒ Object
49 |
# File 'lib/gembrew/config.rb', line 49 def source = data.fetch('source') |
#source_gemspec ⇒ Object
53 |
# File 'lib/gembrew/config.rb', line 53 def source_gemspec = source['gemspec'] || "#{gem_name}.gemspec" |
#source_repo ⇒ Object
51 |
# File 'lib/gembrew/config.rb', line 51 def source_repo = source['repo'] |
#source_tag ⇒ Object
52 |
# File 'lib/gembrew/config.rb', line 52 def source_tag = source['tag'] || "v#{version}" |
#source_type ⇒ Object
50 |
# File 'lib/gembrew/config.rb', line 50 def source_type = source.fetch('type') |
#test_body ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gembrew/config.rb', line 64 def test_body @test_body ||= if data.has_key?('test') data.fetch('test').to_s else test_path = project_path/data.fetch('test_from_file') raise Error, "Test file does not exist: #{test_path}" unless test_path.file? test_path.read end end |
#version ⇒ Object
48 |
# File 'lib/gembrew/config.rb', line 48 def version = data['version']&.to_s |