Class: Kamaze::Project::Tools::Gemspec::Reader

Inherits:
BaseTool show all
Defined in:
lib/kamaze/project/tools/gemspec/reader.rb

Overview

Read gemspec file

Retrieve Gem::Specification through read method.

See Also:

Defined Under Namespace

Classes: Decorator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Kamaze::Project::Tools::BaseTool

Instance Attribute Details

#gem_nameString

Returns:

  • (String)


22
23
24
# File 'lib/kamaze/project/tools/gemspec/reader.rb', line 22

def gem_name
  @gem_name
end

#observer_peersHash|nil (readonly, protected) Originally defined in module Concern::Observable

Returns:

  • (Hash|nil)

#projectObject|Kamaze::Project

Get project

Returns:



57
58
59
# File 'lib/kamaze/project/tools/gemspec/reader.rb', line 57

def project
  @project || Kamaze::Project.instance
end

Instance Method Details

#mutable_attributesObject



27
28
29
# File 'lib/kamaze/project/tools/gemspec/reader.rb', line 27

def mutable_attributes
  [:project, :gem_name]
end

#pwdPathname

Returns:

  • (Pathname)


32
33
34
# File 'lib/kamaze/project/tools/gemspec/reader.rb', line 32

def pwd
  Pathname.new(Dir.pwd)
end

#read(type = nil) ⇒ Gem::Specification|Object

Read gemspec (as given type)

Return Gem::Specification or given type

Parameters:

  • type (nil|Class|Symbol) (defaults to: nil)

Returns:

Raises:

  • (ArgumentError)

    when type is not supported



43
44
45
# File 'lib/kamaze/project/tools/gemspec/reader.rb', line 43

def read(type = nil)
  type ? Decorator.new(spec).to(type) : spec
end

#setupObject (protected)



63
64
65
# File 'lib/kamaze/project/tools/gemspec/reader.rb', line 63

def setup
  @gem_name ||= project.name
end

#specGem::Specification|Object (protected)

Read sepc file.

Returns:

See Also:

  • Gem::Specification.load()


71
72
73
74
75
76
77
# 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

#spec_filePathname

Get (gem)spec file path

Returns:

  • (Pathname)


50
51
52
# File 'lib/kamaze/project/tools/gemspec/reader.rb', line 50

def spec_file
  pwd.join("#{project.name}.gemspec")
end