jewel 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,106 @@
1
1
  # Jewel
2
2
 
3
- Centralize access to Gem information.
3
+ Gem metadata at your fingertips.
4
+
5
+ # What's this for?
6
+
7
+ Sometimes it's useful to access information about a gem at runtime. Jewel exists
8
+ to centralize access to that data and make it as easy as possible to access it.
9
+
10
+ # How do I install it?
11
+
12
+ Latest version:
13
+
14
+ gem install jewel
15
+
16
+ From source:
17
+
18
+ git clone git://github.com/matheusmoreira/jewel.git
19
+
20
+ # How do I use it?
21
+
22
+ Let's say you have a gem named `awesome`. Let's define the `Awesome::Gem` class:
23
+
24
+ # lib/awesome/gem.rb
25
+ require 'jewel'
26
+
27
+ module Awesome
28
+ class Gem < Jewel::Gem
29
+ name! :awesome
30
+ summary 'Awesome gem'
31
+ version '1.2.3'
32
+ homepage 'https://github.com/you/awesome'
33
+
34
+ author 'You'
35
+ email 'you@awesome.com'
36
+
37
+ root '../..' # relative to this file's directory
38
+ files `git ls-files`.split "\n"
39
+
40
+ depend_on :jewel
41
+ end
42
+ end
43
+
44
+ Now you and others can access your specification at runtime. Let's use it to
45
+ set up the `awesome.gemspec` file:
46
+
47
+ #!/usr/bin/env gem build
48
+ # encoding: utf-8
49
+ require './awesome/gem'
50
+
51
+ Awesome::Gem.specification
52
+
53
+ Tools like `gem` and `bundler` assume the `.gemspec` returns a
54
+ `Gem::Specification` instance, which is exactly what is happening here.
55
+
56
+ # External libraries? In _my_ `.gemspec`?!
57
+
58
+ Right. Unlike `.gemspec` generators, Jewel will not duplicate information and it
59
+ will _certainly_ not make a giant mess in your version control diff. These are
60
+ actually some of the reasons why I wrote this gem.
61
+
62
+ However, you will probably run into problems if you use tools that parse your
63
+ `.gemspec` or are unable to `require` your gem. If that's your case, then you'll
64
+ be happy to know that you can also use your existing handwritten
65
+ specification:
66
+
67
+ # lib/awesome/gem.rb
68
+ require 'jewel'
69
+
70
+ module Awesome
71
+ class Gem < Jewel::Gem
72
+ root '../..'
73
+ path_to_gemspec = root.join 'awesome.gemspec'
74
+
75
+ # specification is aliased as spec
76
+ spec ::Gem::Specification.load path_to_gemspec.to_s
77
+ end
78
+ end
79
+
80
+ Hey, is that a `Rails.root`-like method? Exactly! It basically returns a dynamic
81
+ Pathname allows you join paths by chaining methods and passing arguments to
82
+ them:
83
+
84
+ root = Awesome::Gem.root
85
+ root.lib.awesome 'gem.rb' # lib/awesome/gem.rb
86
+ root.i18n I18n.locale.to_s, 'messages.yml' # i18n/en/messages.yml
87
+
88
+ # Nifty. What else can it do?
89
+
90
+ It can make sure that the correct versions of your dependencies will be loaded.
91
+ When you `require` some code, RubyGems will actually load the latest version of
92
+ the gem that it can find, even if you've specified a lower version in the
93
+ specification. To make it load the versions you wanted, you can simply write:
94
+
95
+ Awesome::Gem.activate_dependencies!
96
+
97
+ You can browse the [documentation](http://rubydoc.info/gems/jewel/frames) in
98
+ order to learn more about the general API. There is also [edge
99
+ documentation](http://rubydoc.info/github/matheusmoreira/jewel/master/frames),
100
+ straight from the GitHub repository.
101
+
102
+ # Hey, it's broken!! Why doesn't it do this?
103
+
104
+ Found problems? Have ideas? The best way to get in touch is to [create an
105
+ issue](https://github.com/matheusmoreira/jewel/issues/new) on the GitHub
106
+ tracker. Feel free to fork the repository send a pull request as well!
@@ -1,4 +1,5 @@
1
1
  require 'jewel/gem/metadata'
2
+ require 'jewel/gem/root'
2
3
 
3
4
  module Jewel
4
5
 
@@ -48,7 +49,8 @@ class << Jewel::Gem
48
49
  # caller returns an array of strings that are like “file:line” or “file:line: in `method’”
49
50
  file = caller.first.split(/:/).first
50
51
  directory = File.dirname file
51
- arguments << File.expand_path(relative_to, directory)
52
+ path = File.expand_path(relative_to, directory)
53
+ arguments.push Jewel::Gem::Root.new path
52
54
  end
53
55
  metadata.send :root, *arguments
54
56
  end
@@ -72,6 +74,8 @@ class << Jewel::Gem
72
74
  specification.send method, gem.to_s, *requirements
73
75
  end
74
76
 
77
+ alias depends_on depend_on
78
+
75
79
  # Makes sure the correct versions of this gem's dependencies are loaded at
76
80
  # runtime, no matter which versions are installed locally.
77
81
  #
@@ -128,8 +132,9 @@ end
128
132
  class Jewel::Gem
129
133
 
130
134
  name! :jewel
131
- summary 'Easy access to gem metadata'
132
- version '0.0.4'
135
+ summary 'Gem metadata at your fingertips'
136
+ description 'Jewel provides an easy way to access information about a gem at runtime'
137
+ version '0.0.5'
133
138
  homepage 'https://github.com/matheusmoreira/jewel'
134
139
  license 'Mozilla Public License, version 2.0'
135
140
 
@@ -0,0 +1,25 @@
1
+ require 'pathname'
2
+
3
+ module Jewel
4
+ class Gem
5
+
6
+ # A Pathname that allows subdirectory access through method chaining.
7
+ #
8
+ # @author Matheus Afonso Martins Moreira
9
+ # @since 0.0.5
10
+ class Root < Pathname
11
+
12
+ # Joins the name of the missing method and all arguments with this
13
+ # Pathname.
14
+ #
15
+ # @return [Jewel::Gem::Root] new instance with the results of the join
16
+ def method_missing(method_name, *arguments, &block)
17
+ arguments.unshift method_name.to_s
18
+ pathname = join *arguments
19
+ self.class.new pathname
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jewel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  prerelease:
10
- hash: -3852523161477996427
10
+ hash: -2407718612203325966
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matheus Afonso Martins Moreira
@@ -26,7 +26,7 @@ dependencies:
26
26
  version: '0'
27
27
  segments:
28
28
  - 0
29
- hash: -4447801726355984837
29
+ hash: 4309900643650690816
30
30
  type: :development
31
31
  prerelease: false
32
32
  version_requirements: !ruby/object:Gem::Requirement
@@ -37,7 +37,7 @@ dependencies:
37
37
  version: '0'
38
38
  segments:
39
39
  - 0
40
- hash: -4447801726355984837
40
+ hash: 4309900643650690816
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: redcarpet
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -48,7 +48,7 @@ dependencies:
48
48
  version: '0'
49
49
  segments:
50
50
  - 0
51
- hash: -4447801726355984837
51
+ hash: 4309900643650690816
52
52
  type: :development
53
53
  prerelease: false
54
54
  version_requirements: !ruby/object:Gem::Requirement
@@ -59,7 +59,7 @@ dependencies:
59
59
  version: '0'
60
60
  segments:
61
61
  - 0
62
- hash: -4447801726355984837
62
+ hash: 4309900643650690816
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: rookie
65
65
  requirement: !ruby/object:Gem::Requirement
@@ -70,7 +70,7 @@ dependencies:
70
70
  version: '0'
71
71
  segments:
72
72
  - 0
73
- hash: -4447801726355984837
73
+ hash: 4309900643650690816
74
74
  type: :development
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
@@ -81,7 +81,7 @@ dependencies:
81
81
  version: '0'
82
82
  segments:
83
83
  - 0
84
- hash: -4447801726355984837
84
+ hash: 4309900643650690816
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: rspec
87
87
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +92,7 @@ dependencies:
92
92
  version: '0'
93
93
  segments:
94
94
  - 0
95
- hash: -4447801726355984837
95
+ hash: 4309900643650690816
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
@@ -103,7 +103,7 @@ dependencies:
103
103
  version: '0'
104
104
  segments:
105
105
  - 0
106
- hash: -4447801726355984837
106
+ hash: 4309900643650690816
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: yard
109
109
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ dependencies:
114
114
  version: '0'
115
115
  segments:
116
116
  - 0
117
- hash: -4447801726355984837
117
+ hash: 4309900643650690816
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -125,8 +125,8 @@ dependencies:
125
125
  version: '0'
126
126
  segments:
127
127
  - 0
128
- hash: -4447801726355984837
129
- description:
128
+ hash: 4309900643650690816
129
+ description: Jewel provides an easy way to access information about a gem at runtime
130
130
  email: matheus.a.m.moreira@gmail.com
131
131
  executables: []
132
132
  extensions: []
@@ -142,6 +142,7 @@ files:
142
142
  - lib/jewel.rb
143
143
  - lib/jewel/gem.rb
144
144
  - lib/jewel/gem/metadata.rb
145
+ - lib/jewel/gem/root.rb
145
146
  - spec/jewel/gem_spec.rb
146
147
  homepage: https://github.com/matheusmoreira/jewel
147
148
  licenses:
@@ -158,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
159
  version: '0'
159
160
  segments:
160
161
  - 0
161
- hash: -4447801726355984837
162
+ hash: 4309900643650690816
162
163
  required_rubygems_version: !ruby/object:Gem::Requirement
163
164
  none: false
164
165
  requirements:
@@ -167,11 +168,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  version: '0'
168
169
  segments:
169
170
  - 0
170
- hash: -4447801726355984837
171
+ hash: 4309900643650690816
171
172
  requirements: []
172
173
  rubyforge_project:
173
174
  rubygems_version: 1.8.24
174
175
  signing_key:
175
176
  specification_version: 3
176
- summary: Easy access to gem metadata
177
+ summary: Gem metadata at your fingertips
177
178
  test_files: []