class Kamaze::Project::Tools::Gemspec::Reader

Read “gemspec“ file

Retrieve “Gem::Specification“ through “read“ method.

@see Kamaze::Project

Attributes

gem_name[RW]

@return [String]

project[W]

@return [Kamaze::Project]

Public Instance Methods

mutable_attributes() click to toggle source
# File lib/kamaze/project/tools/gemspec/reader.rb, line 27
def mutable_attributes
  [:project, :gem_name]
end
project() click to toggle source

Get project

@return [Object|Kamaze::Project]

# File lib/kamaze/project/tools/gemspec/reader.rb, line 57
def project
  @project || Kamaze::Project.instance
end
pwd() click to toggle source

@return [Pathname]

# File lib/kamaze/project/tools/gemspec/reader.rb, line 32
def pwd
  Pathname.new(Dir.pwd)
end
read(type = nil) click to toggle source

Read gemspec (as given “type“)

Return “Gem::Specification“ or given “type“

@raise [ArgumentError] when type is not supported @param [nil|Class|Symbol] type @return [Gem::Specification|Object]

# File lib/kamaze/project/tools/gemspec/reader.rb, line 43
def read(type = nil)
  type ? Decorator.new(spec).to(type) : spec
end
spec_file() click to toggle source

Get (gem)spec file path

@return [Pathname]

# File lib/kamaze/project/tools/gemspec/reader.rb, line 50
def spec_file
  pwd.join("#{project.name}.gemspec")
end

Protected Instance Methods

setup() click to toggle source
# File lib/kamaze/project/tools/gemspec/reader.rb, line 63
def setup
  @gem_name ||= project.name
end
spec() click to toggle source

Read sepc file.

@see Gem::Specification.load() @return [Gem::Specification|Object]

# File lib/kamaze/project/tools/gemspec/reader.rb, line 71
def spec
  Dir.chdir(pwd) do
    return Gem::Specification.new unless spec_file.file?

    eval(self.spec_file.read, binding, self.spec_file.to_s) # rubocop:disable Security/Eval
  end
end