Class: Gembrew::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/gembrew/config.rb

Defined Under Namespace

Classes: Dependency

Constant Summary collapse

DEPENDENCY_TAGS =
%w[:macos_only :system_on_macos].freeze
DIRECTORY =
'gembrew'
FILENAME =
'formula.yml'
ALLOWED_KEYS =
%w[
  gem version source output desc homepage license executable dependencies
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, project_path: nil) ⇒ Config

Returns a new instance of Config.



41
42
43
44
45
46
# File 'lib/gembrew/config.rb', line 41

def initialize(path, project_path: nil)
  @path = Pathname(path).expand_path
  @project_path = project_path ? Pathname(project_path).expand_path : @path.dirname.parent
  @data = load_data
  validate
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



19
20
21
# File 'lib/gembrew/config.rb', line 19

def path
  @path
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



19
20
21
# File 'lib/gembrew/config.rb', line 19

def project_path
  @project_path
end

Class Method Details

.all(project_path = Pathname.pwd) ⇒ Object

Raises:



21
22
23
24
25
26
27
# File 'lib/gembrew/config.rb', line 21

def self.all(project_path = Pathname.pwd)
  project_path = Pathname(project_path).expand_path
  paths = (project_path/DIRECTORY).glob("*/#{FILENAME}").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



29
30
31
32
33
# File 'lib/gembrew/config.rb', line 29

def self.find(name, project_path = Pathname.pwd)
  validate_name! name
  project_path = Pathname(project_path).expand_path
  new project_path/DIRECTORY/name/FILENAME, project_path: project_path
end

.validate_name!(name) ⇒ Object

Raises:



35
36
37
38
39
# File 'lib/gembrew/config.rb', line 35

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

#dependenciesObject



62
63
64
# File 'lib/gembrew/config.rb', line 62

def dependencies
  @dependencies ||= data.fetch('dependencies', []).map { |value| parse_dependency value }
end

#descriptionObject



57
# File 'lib/gembrew/config.rb', line 57

def description = data['desc']

#executableObject



60
# File 'lib/gembrew/config.rb', line 60

def executable = data['executable']

#gem_nameObject



49
# File 'lib/gembrew/config.rb', line 49

def gem_name = data.fetch('gem').to_s

#homepageObject



58
# File 'lib/gembrew/config.rb', line 58

def homepage = data['homepage']

#install_extra_bodyObject



66
# File 'lib/gembrew/config.rb', line 66

def install_extra_body = hook_body 'install_extra.rb'

#licenseObject



59
# File 'lib/gembrew/config.rb', line 59

def license = data['license']

#nameObject



48
# File 'lib/gembrew/config.rb', line 48

def name = path.dirname.basename.to_s

#output_pathObject



56
# File 'lib/gembrew/config.rb', line 56

def output_path = (project_path/(data['output'] || "Formula/#{name}.rb")).expand_path

#sourceObject



51
# File 'lib/gembrew/config.rb', line 51

def source = data.fetch('source')

#source_gemspecObject



55
# File 'lib/gembrew/config.rb', line 55

def source_gemspec = source['gemspec'] || "#{gem_name}.gemspec"

#source_repoObject



53
# File 'lib/gembrew/config.rb', line 53

def source_repo = source['repo']

#source_tagObject



54
# File 'lib/gembrew/config.rb', line 54

def source_tag = source['tag'] || "v#{version}"

#source_typeObject



52
# File 'lib/gembrew/config.rb', line 52

def source_type = source.fetch('type')

#test_bodyObject



67
# File 'lib/gembrew/config.rb', line 67

def test_body = hook_body 'test.rb'

#versionObject



50
# File 'lib/gembrew/config.rb', line 50

def version = data['version']&.to_s