Class: Syndi::Jewel::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/syndi/jewel/specification.rb

Overview

A specification for an Syndi jewel (i.e. plugin, extension, etc.).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) {|_self| ... } ⇒ Specification

Construct a new specification.

Parameters:

  • file (String)

    The value of +FILE+ as accessed from the spec itself.

Yields:

  • (_self)

Yield Parameters:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/syndi/jewel/specification.rb', line 32

def initialize file
  @name         = nil
  @version      = nil
  @authors      = []
  @syndi_version = nil
  @our_dir      = File.expand_path('..', file)
  @bundle       = 'Gemfile'
  @code_files   = []
  @doc_files    = []
  @post_message = nil

  @install_do = proc { nil }

  # Yield to block for configuration.
  yield self

  # Initiate installation.
  install
end

Instance Attribute Details

#authorsObject

Returns the value of attribute authors.



19
20
21
# File 'lib/syndi/jewel/specification.rb', line 19

def authors
  @authors
end

#bundleObject

Returns the value of attribute bundle.



19
20
21
# File 'lib/syndi/jewel/specification.rb', line 19

def bundle
  @bundle
end

#code_filesObject (readonly)

Returns the value of attribute code_files.



19
20
21
# File 'lib/syndi/jewel/specification.rb', line 19

def code_files
  @code_files
end

#doc_filesObject (readonly)

Returns the value of attribute doc_files.



19
20
21
# File 'lib/syndi/jewel/specification.rb', line 19

def doc_files
  @doc_files
end

#install_doObject (readonly)

Returns the value of attribute install_do.



19
20
21
# File 'lib/syndi/jewel/specification.rb', line 19

def install_do
  @install_do
end

#nameObject

A specification for an Syndi jewel (i.e. plugin, extension, etc.).



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/syndi/jewel/specification.rb', line 17

class Specification

  attr_reader :name, :version, :authors, :syndi_version, :our_dir,
              :bundle, :code_files, :doc_files, :post_message,
              :install_do

  def omg *args
    args.each do |unicorn|
      puts "==> #{unicorn}".magenta
    end
  end

  # Construct a new specification.
  #
  # @param [String] file The value of +__FILE__+ as accessed from the spec itself.
  def initialize file
    @name         = nil
    @version      = nil
    @authors      = []
    @syndi_version = nil
    @our_dir      = File.expand_path('..', file)
    @bundle       = 'Gemfile'
    @code_files   = []
    @doc_files    = []
    @post_message = nil

    @install_do = proc { nil }

    # Yield to block for configuration.
    yield self

    # Initiate installation.
    install
  end

  # Sets the jewel name.
  #
  # @param [String] monkey The name of the jewel.
  def name= monkey
    raise JewelError, 'Invalid jewel name!' unless monkey.instance_of? String
    monkey.downcase!
    
    @name = monkey
    omg "Jewel name: #{monkey.green}"
  end

  # Sets the jewel version.
  #
  # @param [String] mascara The version of the jewel.
  def version= mascara
    mascara.downcase!

    @version = mascara
    omg "Jewel version: #{mascara.green}"
  end

  # Sets the jewel author (only one).
  #
  # @param [String] its_a_trap The (sole) author of the jewel.
  def author= its_a_trap
    raise JewelError, 'Invalid jewel author!' unless its_a_trap.instance_of? String

    @authors.push its_a_trap
    omg "Jewel written by #{its_a_trap.blue}"
  end

  # Sets multiple jewel authors.
  #
  # @param [Array] chi The authors of the jewel. (splat)
  def authors= *chi
    raise JewelError, 'Invalid jewel author list!'              unless chi.instance_of? Array
    raise JewelError, 'Invalid method of author specification!' unless chi.length > 1

    @authors = chi
    omg "Jewel written by #{chi.join ', '}"
  end

  # Sets the Syndi version required by the jewel.
  #
  # @param [String] essie The minimum Syndi version required.
  def syndi_version= essie
    if Gem::Version.new(essie.dup) < Gem::Version.new(Syndi::VERSION.dup)
      raise JewelError, "This jewel requires Syndi version >= #{essie.red} but current version is #{Syndi::VERSION}!"
    end

    @syndi_version = essie
    omg "Jewel is compatible with your version of Syndi (requires: >= #{essie.green})!"
  end

  # Sets the name of the GemBundler Gemfile. Default is +Gemfile+.
  #
  # @param [String] sephora The name of the Gemfile.
  def bundle= sephora = 'Gemfile'
    raise JewelError, "Jewel's Gemfile is missing!" unless File.exists? File.join(@our_dir, sephora)

    @bundle = sephora
  end

end

#our_dirObject (readonly)

Returns the value of attribute our_dir.



19
20
21
# File 'lib/syndi/jewel/specification.rb', line 19

def our_dir
  @our_dir
end

#post_messageObject (readonly)

Returns the value of attribute post_message.



19
20
21
# File 'lib/syndi/jewel/specification.rb', line 19

def post_message
  @post_message
end

#syndi_versionObject

Returns the value of attribute syndi_version.



19
20
21
# File 'lib/syndi/jewel/specification.rb', line 19

def syndi_version
  @syndi_version
end

#versionObject

Returns the value of attribute version.



19
20
21
# File 'lib/syndi/jewel/specification.rb', line 19

def version
  @version
end

Instance Method Details

#author=(its_a_trap) ⇒ Object

Sets the jewel author (only one).

Parameters:

  • its_a_trap (String)

    The (sole) author of the jewel.

Raises:



76
77
78
79
80
81
# File 'lib/syndi/jewel/specification.rb', line 76

def author= its_a_trap
  raise JewelError, 'Invalid jewel author!' unless its_a_trap.instance_of? String

  @authors.push its_a_trap
  omg "Jewel written by #{its_a_trap.blue}"
end

#omg(*args) ⇒ Object



23
24
25
26
27
# File 'lib/syndi/jewel/specification.rb', line 23

def omg *args
  args.each do |unicorn|
    puts "==> #{unicorn}".magenta
  end
end