Class: Spade::Packager::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/spade/packager/package.rb

Constant Summary collapse

EXT =
"spd"
METADATA =
%w[keywords licenses engines main bin directories]
FIELDS =
%w[name version description author homepage summary]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email = "") ⇒ Package

Returns a new instance of Package.



11
12
13
# File 'lib/spade/packager/package.rb', line 11

def initialize(email = "")
  @email = email
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



8
9
10
# File 'lib/spade/packager/package.rb', line 8

def attributes
  @attributes
end

#dependenciesObject

Returns the value of attribute dependencies.



8
9
10
# File 'lib/spade/packager/package.rb', line 8

def dependencies
  @dependencies
end

#directoriesObject

Returns the value of attribute directories.



8
9
10
# File 'lib/spade/packager/package.rb', line 8

def directories
  @directories
end

#errorsObject

Returns the value of attribute errors.



8
9
10
# File 'lib/spade/packager/package.rb', line 8

def errors
  @errors
end

#json_pathObject

Returns the value of attribute json_path.



8
9
10
# File 'lib/spade/packager/package.rb', line 8

def json_path
  @json_path
end

#lib_path=(value) ⇒ Object

Sets the attribute lib_path

Parameters:

  • value

    the value to set the attribute lib_path to.



8
9
10
# File 'lib/spade/packager/package.rb', line 8

def lib_path=(value)
  @lib_path = value
end

#metadataObject

Returns the value of attribute metadata.



8
9
10
# File 'lib/spade/packager/package.rb', line 8

def 
  @metadata
end

#test_path=(value) ⇒ Object

Sets the attribute test_path

Parameters:

  • value

    the value to set the attribute test_path to.



8
9
10
# File 'lib/spade/packager/package.rb', line 8

def test_path=(value)
  @test_path = value
end

Instance Method Details

#as_json(options = {}) ⇒ Object



43
44
45
46
47
48
# File 'lib/spade/packager/package.rb', line 43

def as_json(options = {})
  json = self..clone
  FIELDS.each{|key| json[key] = send(key)}
  json["dependencies"] = self.dependencies
  json
end

#spade=(path) ⇒ Object



15
16
17
18
# File 'lib/spade/packager/package.rb', line 15

def spade=(path)
  format = LibGems::Format.from_file_by_path(path)
  fill_from_gemspec(format.spec)
end

#to_extObject



54
55
56
# File 'lib/spade/packager/package.rb', line 54

def to_ext
  "#{self.to_full_name}.#{EXT}"
end

#to_full_nameObject



50
51
52
# File 'lib/spade/packager/package.rb', line 50

def to_full_name
  "#{name}-#{version}"
end

#to_specObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/spade/packager/package.rb', line 20

def to_spec
  return unless valid?
  LibGems::Specification.new do |spec|
    spec.name              = name
    spec.version           = version
    spec.authors           = [author]
    spec.email             = @email
    spec.homepage          = homepage
    spec.summary           = summary
    spec.description       = description
    spec.requirements      = [.to_json]
    spec.files             = directory_files + ["package.json"]
    spec.test_files        = glob_files(test_path) if test_path
    spec.bindir            = bin_path
    spec.executables       = bin_files.map{|p| File.basename(p) } if bin_path
    spec.rubyforge_project = "spade"
    def spec.file_name
      "#{full_name}.#{EXT}"
    end
    dependencies.each{|d,v| spec.add_dependency(d, v) } if dependencies
  end
end

#valid?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/spade/packager/package.rb', line 66

def valid?
  read && parse && validate
end

#validateObject



62
63
64
# File 'lib/spade/packager/package.rb', line 62

def validate
  validate_fields && validate_version && validate_paths
end