jewel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
File without changes
data/lib/jewel.rb CHANGED
@@ -1,6 +1,7 @@
1
- # Provides easy access to Gem metadata in an object oriented fashion.
1
+ # Easy, object-oriented access to gem metadata.
2
2
  #
3
3
  # @author Matheus Afonso Martins Moreira
4
+ # @see Jewel::Gem
4
5
  # @since 0.0.1
5
6
  module Jewel
6
7
  end
data/lib/jewel/gem.rb CHANGED
@@ -2,7 +2,7 @@ require 'jewel/gem/metadata'
2
2
 
3
3
  module Jewel
4
4
 
5
- # The centralized spot for information about a gem.
5
+ # Stores information about a gem.
6
6
  #
7
7
  # @author Matheus Afonso Martins Moreira
8
8
  # @since 0.0.1
@@ -20,38 +20,74 @@ class << Jewel::Gem
20
20
  @metadata ||= Jewel::Gem::Metadata.new
21
21
  end
22
22
 
23
- # Forwards everything to this Gem's metadata.
23
+ # Forwards everything to this gem's {metadata}.
24
24
  def method_missing(method_name, *arguments, &block)
25
25
  metadata.send method_name, *arguments, &block
26
26
  end
27
27
 
28
- # Sets the name of the gem.
28
+ # Sets the name of the gem. Returns the name if not given an argument.
29
29
  #
30
- # @param [String, Symbol, #to_s] name the name of the library
31
- # @return [String]
30
+ # @param [String, Symbol, #to_s] name the name of the gem
31
+ # @return [String] the name of the gem
32
32
  def name!(name = nil)
33
33
  arguments = [ name ].compact.map &:to_s
34
34
  metadata.send :name, *arguments
35
35
  end
36
36
 
37
+ # Sets the root of the gem, relative to the directory where the current file
38
+ # is located. Returns the gem root if not given an argument.
39
+ #
40
+ # @param [String, #to_s] relative_to the gem root relative to the current
41
+ # directory
42
+ # @return [String] the gem root as an absolute path
43
+ # @since 0.0.2
44
+ def root(relative_to = nil)
45
+ arguments = []
46
+ arguments << File.expand_path(relative_to.to_s, File.dirname(__FILE__)) unless relative_to.nil?
47
+ metadata.send :root, *arguments
48
+ end
49
+
37
50
  # Adds a runtime dependency.
38
51
  #
39
52
  # If called within a {development} context, a development dependency will be
40
53
  # added instead.
41
54
  #
42
- # @param [String, Symbol] gem the name of the gem
43
- # @param [String] version the version of the gem
55
+ # @param [String, Symbol, #to_s] gem the name of the gem
56
+ # @param [String, Symbol, #to_s] version the version of the gem
57
+ # @see development
58
+ # @example
59
+ # depend_on :jewel # runtime dependency
60
+ #
61
+ # development do
62
+ # depend_on :rspec # development dependency
63
+ # end
44
64
  def depend_on(gem, version = nil)
45
65
  metadata.send(if development?
46
66
  :development_dependencies
47
67
  else :dependencies end).merge! gem => version
48
68
  end
49
69
 
70
+ # Makes sure the correct versions of this gem's dependencies are loaded at
71
+ # runtime, no matter which versions are installed locally.
72
+ #
73
+ # @option options [true, false, :only] :development (false) which set of
74
+ # dependencies should be activated
75
+ # @since 0.0.2
76
+ def activate_dependencies!(options = {})
77
+ metadata.each_dependency options do |name, version|
78
+ gem name, version unless version.nil?
79
+ end
80
+ end
81
+
50
82
  # Executes the given block within a development context, turning runtime
51
83
  # dependencies into development dependencies.
52
84
  #
53
- # @yield nothing
85
+ # @param [Proc] block the block to evaluate
54
86
  # @see depend_on
87
+ # @example
88
+ # development do
89
+ # depend_on :rspec
90
+ # end
55
91
  def development(&block)
56
92
  @development = true
57
93
  instance_eval &block
@@ -61,8 +97,8 @@ class << Jewel::Gem
61
97
 
62
98
  # Returns this gem's specification.
63
99
  #
64
- # @return [Gem::Specification] the gem specification
65
- # @see Jewel::Gem::Metadata.to_spec
100
+ # @return [::Gem::Specification] the gem specification
101
+ # @see Jewel::Gem::Metadata#to_spec
66
102
  def spec
67
103
  metadata.to_spec
68
104
  end
@@ -84,15 +120,17 @@ end
84
120
 
85
121
  class Jewel::Gem
86
122
 
87
- name! 'jewel'
88
- summary 'Easy access to Gem metadata'
89
- version '0.0.1'
123
+ name! :jewel
124
+ summary 'Easy access to gem metadata'
125
+ version '0.0.2'
90
126
  homepage 'https://github.com/matheusmoreira/jewel'
127
+ license 'Mozilla Public License, version 2.0'
91
128
 
92
129
  author 'Matheus Afonso Martins Moreira'
93
130
  email 'matheus.a.m.moreira@gmail.com'
94
131
 
95
132
  files `git ls-files`.split "\n"
133
+ root '../..'
96
134
 
97
135
  development do
98
136
  depend_on :bundler
@@ -13,14 +13,11 @@ module Jewel
13
13
  # instance.
14
14
  #
15
15
  # @param [Proc] block the initializer block
16
- # @since 0.0.1
17
16
  def initialize(&block)
18
17
  instance_eval &block unless block.nil?
19
18
  end
20
19
 
21
20
  # Associates the name of the missing method with the given arguments.
22
- #
23
- # @since 0.0.1
24
21
  def method_missing(method_name, *arguments, &block)
25
22
  method = method_name.to_s.gsub(/[=?!\z]/ix, '').strip.intern
26
23
  count = arguments.count
@@ -32,7 +29,6 @@ module Jewel
32
29
  # This gem's runtime dependencies.
33
30
  #
34
31
  # @return [Hash] name => version pairs
35
- # @since 0.0.1
36
32
  def dependencies
37
33
  @dependencies ||= {}
38
34
  end
@@ -40,31 +36,59 @@ module Jewel
40
36
  # This gem's development dependencies.
41
37
  #
42
38
  # @return [Hash] name => version pairs
43
- # @since 0.0.1
44
39
  def development_dependencies
45
40
  @development_dependencies ||= {}
46
41
  end
47
42
 
48
- # Use the stored information to generate a Gem::Specification.
43
+ # Runtime and development dependencies. The former takes precedence,
44
+ # should version requirements conflict.
45
+ #
46
+ # @return [Hash] name => version pairs
47
+ # @since 0.0.2
48
+ def all_dependencies
49
+ development_dependencies.merge dependencies
50
+ end
51
+
52
+ # Yields dependencies to the given block, or returns an enumerator.
49
53
  #
50
- # @return [Gem::Specification] the specification
51
- # @since 0.0.1
54
+ # @option options [true, false, :only] :development (false) whether
55
+ # runtime and development dependencies should be included
56
+ # @yieldparam [String] gem_name the name of the gem
57
+ # @yieldparam [String, nil] version the required version
58
+ # @since 0.0.2
59
+ def each_dependency(options = {})
60
+ return enum_for :each_dependency, options unless block_given?
61
+ development = options.fetch :development, false
62
+ case development
63
+ when :only then development_dependencies
64
+ when true then all_dependencies
65
+ else dependencies
66
+ end.each do |gem_name, version|
67
+ yield gem_name.to_s, version
68
+ end
69
+ end
70
+
71
+ # Uses the stored information to generate a ::Gem::Specification.
72
+ #
73
+ # @return [::Gem::Specification] the specification
52
74
  def to_spec
53
75
  ::Gem::Specification.new do |gem_specification|
54
76
 
55
77
  # Set all attributes
56
78
  stored_attributes.keys.each do |key|
57
- writer = '='.prepend key.to_s
58
- gem_specification.send writer, stored_attributes[key] if gem_specification.respond_to? writer
79
+ writer_method = '='.prepend(key.to_s).intern
80
+ if gem_specification.respond_to? writer_method
81
+ gem_specification.send writer_method, stored_attributes[key]
82
+ end
59
83
  end
60
84
 
61
85
  # Add the dependencies
62
86
  {
63
- :add_runtime_dependency => dependencies,
64
- :add_development_dependency => development_dependencies
65
- }.each do |method_name, dependencies|
66
- dependencies.each do |gem_name, version|
67
- gem_specification.send method_name.intern, gem_name.to_s, version
87
+ :add_runtime_dependency => false,
88
+ :add_development_dependency => :only
89
+ }.each do |method, option|
90
+ each_dependency development: option do |*arguments|
91
+ gem_specification.send method, *arguments.compact
68
92
  end
69
93
  end
70
94
  end
@@ -75,7 +99,6 @@ module Jewel
75
99
  # The stored gem attributes.
76
100
  #
77
101
  # @return [Hash] hash holding information about the gem
78
- # @since 0.0.1
79
102
  def stored_attributes
80
103
  @stored_attributes ||= {}
81
104
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jewel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-05 00:00:00.000000000 Z
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -84,7 +84,7 @@ files:
84
84
  - .gitignore
85
85
  - .rvmrc
86
86
  - Gemfile
87
- - LICENSE.MPL2
87
+ - LICENSE.MPLv2.0
88
88
  - README.markdown
89
89
  - Rakefile
90
90
  - jewel.gemspec
@@ -92,7 +92,8 @@ files:
92
92
  - lib/jewel/gem.rb
93
93
  - lib/jewel/gem/metadata.rb
94
94
  homepage: https://github.com/matheusmoreira/jewel
95
- licenses: []
95
+ licenses:
96
+ - Mozilla Public License, version 2.0
96
97
  post_install_message:
97
98
  rdoc_options: []
98
99
  require_paths:
@@ -105,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
106
  version: '0'
106
107
  segments:
107
108
  - 0
108
- hash: 2841041591828843644
109
+ hash: 1007763749711895978
109
110
  required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  none: false
111
112
  requirements:
@@ -114,11 +115,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  version: '0'
115
116
  segments:
116
117
  - 0
117
- hash: 2841041591828843644
118
+ hash: 1007763749711895978
118
119
  requirements: []
119
120
  rubyforge_project:
120
121
  rubygems_version: 1.8.24
121
122
  signing_key:
122
123
  specification_version: 3
123
- summary: Easy access to Gem metadata
124
+ summary: Easy access to gem metadata
124
125
  test_files: []