contextify 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ ÷G�c=HC�aS�Mp�8_��H��2�#aS��@ R����I0�Hޯ��-�� ���(����J����'���j
2
+ ϓÂ�.��J��8�ӓ4>dw�ċ�"������i.3K�0�_cwd���X�E99l�W8g׶������0$3����&I�U�q̕�J�֫�����L�"Ч(Ѳ 7gd��w@������AE%�֑�z�E�x$�o1�a�׉��p)X�@����NO!w@
@@ -1,3 +1,14 @@
1
+ === 0.1.3 / 2009-09-21
2
+
3
+ * Require Hoe >= 2.3.3.
4
+ * Require YARD >= 0.2.3.5.
5
+ * Require RSpec >= 1.2.8.
6
+ * Use 'hoe/signing' for signed RubyGems.
7
+ * Moved to YARD based documentation.
8
+ * Added YARD handlers for documenting contextify method calls.
9
+ * Allow self.load_context to load objects that inherit from the contextified class.
10
+ * All specs pass on JRuby 1.3.1.
11
+
1
12
  === 0.1.2 / 2009-02-06
2
13
 
3
14
  * Added self.load_context_block to Contextify.
@@ -12,6 +12,12 @@ lib/contextify/extensions/meta/object.rb
12
12
  lib/contextify/pending_context.rb
13
13
  lib/contextify/contextify.rb
14
14
  lib/contextify/version.rb
15
+ lib/contextify/yard.rb
16
+ lib/contextify/yard/handlers.rb
17
+ lib/contextify/yard/handlers/ruby.rb
18
+ lib/contextify/yard/handlers/ruby/contextify_handler.rb
19
+ lib/contextify/yard/handlers/ruby/legacy.rb
20
+ lib/contextify/yard/handlers/ruby/legacy/contextify_handler.rb
15
21
  spec/contextify_spec.rb
16
22
  spec/spec_helper.rb
17
23
  tasks/spec.rb
data/README.txt CHANGED
@@ -1,7 +1,8 @@
1
- = contextify
1
+ = Contextify
2
2
 
3
3
  * http://contextify.rubyforge.org/
4
4
  * http://github.com/postmodern/contextify/
5
+ * Postmodern (postmodern.mod3 at gmail.com)
5
6
 
6
7
  == DESCRIPTION:
7
8
 
@@ -17,7 +18,7 @@ classes named like the file.
17
18
 
18
19
  contextify :controller
19
20
 
20
- ...
21
+ # ...
21
22
 
22
23
  end
23
24
 
@@ -34,13 +35,19 @@ classes named like the file.
34
35
 
35
36
  end
36
37
 
38
+ # load a Controller object from a file.
37
39
  controller = Controller.load_context('my_controller.rb')
38
40
  # => #<Controller: ...>
41
+
39
42
  controller.test1
40
43
  # => "This is the first test"
41
44
  controller.test2('one two three')
42
45
  # => "Hello one two three"
43
46
 
47
+ == REQUIREMENTS:
48
+
49
+ * {YARD}[http://yard.soen.ca/] >= 0.2.3.5
50
+
44
51
  == INSTALL:
45
52
 
46
53
  $ sudo gem install contextify
data/Rakefile CHANGED
@@ -2,13 +2,23 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
+ require 'hoe/signing'
5
6
  require './tasks/spec.rb'
6
- require './lib/contextify/version.rb'
7
+ require './tasks/yard.rb'
7
8
 
8
- Hoe.new('contextify', Contextify::VERSION) do |p|
9
- p.rubyforge_name = 'contextify'
10
- p.developer('Postmodern', 'postmodern.mod3@gmail.com')
11
- p.remote_rdoc_dir = ''
9
+ Hoe.spec('contextify') do
10
+ self.rubyforge_name = 'contextify'
11
+ self.developer('Postmodern', 'postmodern.mod3@gmail.com')
12
+ self.remote_rdoc_dir = ''
13
+ self.extra_deps = [
14
+ ['yard', '>=0.2.3.5']
15
+ ]
16
+
17
+ self.extra_dev_deps = [
18
+ ['rspec', '>=1.2.8']
19
+ ]
20
+
21
+ self.spec_extras = {:has_rdoc => 'yard'}
12
22
  end
13
23
 
14
24
  # vim: syntax=Ruby
@@ -5,6 +5,12 @@ require 'contextify/pending_context'
5
5
  module Contextify
6
6
  def self.included(base)
7
7
  base.module_eval do
8
+ #
9
+ # Contextifies the class.
10
+ #
11
+ # @param [Symbol, String] name
12
+ # The context name to assign to the class.
13
+ #
8
14
  def self.contextify(name)
9
15
  name = name.to_s
10
16
 
@@ -17,7 +23,17 @@ module Contextify
17
23
  end
18
24
 
19
25
  meta_def(:load_context) do |path,*args|
20
- Contextify.load_context(self.context_name,path,*args)
26
+ pending = Contextify.load_blocks(path)
27
+
28
+ context, block = pending.blocks.find do |name,block|
29
+ Contextify.contexts[name].ancestors.include?(self)
30
+ end
31
+
32
+ if (context && block)
33
+ obj = Contextify.contexts[name].new(*args)
34
+ obj.instance_eval(&block)
35
+ obj
36
+ end
21
37
  end
22
38
 
23
39
  # define the top-level context wrappers
@@ -37,44 +53,67 @@ module Contextify
37
53
  end
38
54
 
39
55
  #
40
- # Returns a Hash of all defined contexts.
56
+ # All contextified classes.
57
+ #
58
+ # @return [Hash{Symbol => Class}]
59
+ # All defined contexts and their classes.
41
60
  #
42
61
  def Contextify.contexts
43
62
  @@contextify_contexts ||= {}
44
63
  end
45
64
 
46
65
  #
47
- # Returns +true+ if there is a context defined with the specified
48
- # _name_, returns +false+ otherwise.
66
+ # Determines whether a context with a specific name has been defined.
67
+ #
68
+ # @param [Symbol, String] name
69
+ # The name of the context to search for.
70
+ #
71
+ # @return [Boolean]
72
+ # Specifies whether there is a context defined with the specified
73
+ # name.
49
74
  #
50
75
  def Contextify.is_context?(name)
51
76
  Contextify.contexts.has_key?(name.to_s)
52
77
  end
53
78
 
54
79
  #
55
- # Returns the Array of contexts which are waiting to be loaded.
80
+ # The contexts waiting to be fully loaded.
81
+ #
82
+ # @return [Array<PendingContext>]
83
+ # Contexts which are waiting to be loaded.
56
84
  #
57
85
  def Contextify.waiting
58
86
  @@contextify_waiting_contexts ||= []
59
87
  end
60
88
 
61
89
  #
62
- # Returns the pending context being loaded.
90
+ # The first context waiting to be fully loaded.
91
+ #
92
+ # @return [PendingContext]
93
+ # The pending context being loaded.
63
94
  #
64
95
  def Contextify.pending
65
96
  Contextify.waiting.first
66
97
  end
67
98
 
68
99
  #
69
- # Returns +true+ if there is a pending context present, returns
70
- # +false+ otherwise.
100
+ # Determines whether there are pending contexts.
101
+ #
102
+ # @return [Boolean]
103
+ # Specifies whether there is a pending context present.
71
104
  #
72
105
  def Contextify.is_pending?
73
106
  !(Contextify.waiting.empty?)
74
107
  end
75
108
 
76
109
  #
77
- # Returns the first pending context with the specified _path_.
110
+ # Finds the first pending context being loaded from a specific path.
111
+ #
112
+ # @param [String] path
113
+ # The path which is being loaded.
114
+ #
115
+ # @return [PendingContext]
116
+ # The first pending context with the specified path.
78
117
  #
79
118
  def Contextify.loading(path)
80
119
  Contextify.waiting.each do |pending|
@@ -87,16 +126,27 @@ module Contextify
87
126
  end
88
127
 
89
128
  #
90
- # Returns +true+ if the pending context with the specified _path_
91
- # is present, returns +false+ otherwise.
129
+ # Determines whether contexts are being loaded from a specific path.
130
+ #
131
+ # @param [String] path
132
+ # The path to check if contexts are being loaded from.
133
+ #
134
+ # @return [Boolean]
135
+ # Specifies whether pending contexts are being loaded from the
136
+ # specified path.
92
137
  #
93
138
  def Contextify.is_loading?(path)
94
139
  !(Contextify.loading(path).nil?)
95
140
  end
96
141
 
97
142
  #
98
- # Loads all context blocks from the specified _path_, returning a
99
- # PendingContext object containing the context blocks.
143
+ # Loads all context blocks from a specific path.
144
+ #
145
+ # @param [String] path
146
+ # The path to load all context blocks from.
147
+ #
148
+ # @return [PendingContext]
149
+ # The pending context which contains the blocks.
100
150
  #
101
151
  def Contextify.load_blocks(path,&block)
102
152
  path = File.expand_path(path)
@@ -121,15 +171,31 @@ module Contextify
121
171
  end
122
172
 
123
173
  #
124
- # Loads the context block of the specified _name_ from the specified
125
- # _path_, returning the context block. If a _block_ is given it will
126
- # be passed the loaded context block.
174
+ # Loads the context block for the context with the specific name
175
+ # from a specific path.
176
+ #
177
+ # @param [Symbol, String] name
178
+ # The name of the context to load the block for.
179
+ #
180
+ # @param [String] path
181
+ # The path to load the context block from.
182
+ #
183
+ # @yield [block]
184
+ # The block which will receive the context block.
185
+ #
186
+ # @yieldparam [Proc] block
187
+ # The context block loaded from the specified _path_.
188
+ #
189
+ # @return [Proc]
190
+ # The block for the context with the specified _name_.
127
191
  #
128
- # Contextify.load_block(:exploit,'/path/to/my_exploit.rb') # => Proc
192
+ # @example
193
+ # Contextify.load_block(:exploit,'/path/to/my_exploit.rb')
194
+ # # => Proc
129
195
  #
130
- # Contextify.load_block(:shellcode,'/path/to/my_shellcode.rb')
131
- # do |block|
132
- # ...
196
+ # @example
197
+ # Contextify.load_block(:shellcode,'/path/to/execve.rb') do |block|
198
+ # # ...
133
199
  # end
134
200
  #
135
201
  def Contextify.load_block(name,path,&block)
@@ -140,20 +206,33 @@ module Contextify
140
206
  end
141
207
 
142
208
  #
143
- # Loads the context of the specified _name_ and from the specified
144
- # _path_ with the given _args_. If no contexts were defined with the
145
- # specified _name_, an UnknownContext exception will be raised.
209
+ # Loads the context object of a specific name and from the specific
210
+ # path.
146
211
  #
147
- # Contextify.load_context(:note,'/path/to/my_notes.rb') # => Note
212
+ # @param [Symbol, String] name
213
+ # The name of the context to load.
148
214
  #
149
- def Contextify.load_context(name,path,*args)
215
+ # @param [String] path
216
+ # The path to load the context object from.
217
+ #
218
+ # @return [Object]
219
+ # The loaded context object.
220
+ #
221
+ # @raise [UnknownContext]
222
+ # No context was defined with the specific name.
223
+ #
224
+ # @example
225
+ # Contextify.load_context(:note,'/path/to/my_notes.rb')
226
+ # # => Note
227
+ #
228
+ def Contextify.load_context(name,path,*arguments)
150
229
  name = name.to_s
151
230
 
152
231
  unless Contextify.is_context?(name)
153
232
  raise(UnknownContext,"unknown context #{name.dump}",caller)
154
233
  end
155
234
 
156
- new_context = Contextify.contexts[name].new(*args)
235
+ new_context = Contextify.contexts[name].new(*arguments)
157
236
 
158
237
  Contextify.load_block(name,path) do |context_block|
159
238
  new_context.instance_eval(&context_block) if context_block
@@ -163,11 +242,17 @@ module Contextify
163
242
  end
164
243
 
165
244
  #
166
- # Loads all contexts from the specified _path_ returning an +Array+
167
- # of loaded contexts. If a _block_ is given, it will be passed
168
- # each loaded context.
245
+ # Loads all context objects from a specific path.
246
+ #
247
+ # @param [String] path
248
+ # The path to load all context objects from.
249
+ #
250
+ # @return [Array]
251
+ # The array of loaded context objects.
169
252
  #
170
- # Contextify.load_contexts('/path/to/misc_contexts.rb') # => [...]
253
+ # @example
254
+ # Contextify.load_contexts('/path/to/misc_contexts.rb')
255
+ # # => [...]
171
256
  #
172
257
  def Contextify.load_contexts(path,&block)
173
258
  new_objs = []
@@ -1,4 +1,4 @@
1
1
  module Contextify
2
- class ContextNotFound < RuntimeError
2
+ class ContextNotFound < StandardError
3
3
  end
4
4
  end
@@ -1,4 +1,4 @@
1
1
  module Contextify
2
- class UnknownContext < RuntimeError
2
+ class UnknownContext < StandardError
3
3
  end
4
4
  end
@@ -8,7 +8,10 @@ module Contextify
8
8
  attr_accessor :blocks
9
9
 
10
10
  #
11
- # Creates a new PendingContext object with the specified _path_.
11
+ # Creates a new PendingContext object.
12
+ #
13
+ # @param [String] path
14
+ # The path the pending context was loaded from.
12
15
  #
13
16
  def initialize(path)
14
17
  @path = File.expand_path(path)
@@ -16,8 +19,13 @@ module Contextify
16
19
  end
17
20
 
18
21
  #
19
- # Iterates over each block in the pending context, passing their name
20
- # and value to the given _block_.
22
+ # Iterates over each block in the pending context.
23
+ #
24
+ # @yield [block]
25
+ # The block will be passed each pending context block.
26
+ #
27
+ # @yieldparam [Proc] block
28
+ # A pending context block.
21
29
  #
22
30
  def each_block(&block)
23
31
  @blocks.each(&block)
@@ -1,3 +1,3 @@
1
1
  module Contextify
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -0,0 +1 @@
1
+ require 'contextify/yard/handlers'
@@ -0,0 +1 @@
1
+ require 'contextify/yard/handlers/ruby'
@@ -0,0 +1,2 @@
1
+ require 'contextify/yard/handlers/ruby/contextify_handler'
2
+ require 'contextify/yard/handlers/ruby/legacy'
@@ -0,0 +1,33 @@
1
+ require 'yard'
2
+
3
+ module YARD
4
+ module Handlers
5
+ module Ruby
6
+ class ContextifyHandler < Base
7
+
8
+ handles method_call(:contextify)
9
+
10
+ def process
11
+ nobj = ModuleObject.new(:root, 'Kernel')
12
+ obj = statement.parameters(false).first
13
+
14
+ mscope = scope
15
+ name = case obj.type
16
+ when :symbol_literal
17
+ obj.jump(:ident, :op, :kw, :const).source
18
+ when :string_literal
19
+ obj.jump(:string_content).source
20
+ end
21
+
22
+ register MethodObject.new(nobj, name, mscope) do |o|
23
+ o.visibility = :public
24
+ o.source = statement.source
25
+ o.signature = "def #{name}(&block)"
26
+ o.parameters = [['&block', nil]]
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ require 'contextify/yard/handlers/ruby/legacy/contextify_handler'
@@ -0,0 +1,29 @@
1
+ require 'yard'
2
+
3
+ module YARD
4
+ module Handlers
5
+ module Ruby
6
+ module Legacy
7
+ class ContextifyHandler < Base
8
+
9
+ handles /\Acontextify\s/
10
+
11
+ def process
12
+ nobj = ModuleObject.new(:root, 'Kernel')
13
+
14
+ mscope = scope
15
+ name = statement.tokens[2,1].to_s[1..-1]
16
+
17
+ register MethodObject.new(nobj, name, mscope) do |o|
18
+ o.visibility = :public
19
+ o.source = statement.source
20
+ o.signature = "def #{name}(&block)"
21
+ o.parameters = [['&block', nil]]
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -65,6 +65,10 @@ describe Contextify do
65
65
  book.class.should == Book
66
66
  end
67
67
 
68
+ it "should return nil when loading contexts incompatible with the class" do
69
+ BookReview.load_context(@snow_crash_path).should be_nil
70
+ end
71
+
68
72
  describe "loaded contexts" do
69
73
  before(:all) do
70
74
  @book = Book.load_context(@snow_crash_path)
@@ -6,4 +6,5 @@ Spec::Rake::SpecTask.new(:spec) do |t|
6
6
  t.spec_opts = ['--colour', '--format', 'specdoc']
7
7
  end
8
8
 
9
+ task :test => :spec
9
10
  task :default => :spec
metadata CHANGED
@@ -1,17 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contextify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1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TH8jnzN92HzEK5WdScm1QpZKF1e
27
+ cezArMbxbSPaosxTCtG6LQTkE28lFQsmFZ5xzouugS4h5+LVJiVMmiP+l3EfkjFa
28
+ GOURU+rNEMPWo8MCWivGW7jes6BMzWHcW7DQ0scNVmIcCIgdyMmpscuAEOSeghy9
29
+ /fFs57Ey2OXBL55nDOyvN/ZQ2Vab05UH4t+GCxjAPeirzL/29FBtePT6VD44c38j
30
+ pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
31
+ -----END CERTIFICATE-----
11
32
 
12
- date: 2009-02-06 00:00:00 -08:00
33
+ date: 2009-09-25 00:00:00 -07:00
13
34
  default_executable:
14
35
  dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.2.3.5
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ type: :development
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.8
55
+ version:
15
56
  - !ruby/object:Gem::Dependency
16
57
  name: hoe
17
58
  type: :development
@@ -20,9 +61,11 @@ dependencies:
20
61
  requirements:
21
62
  - - ">="
22
63
  - !ruby/object:Gem::Version
23
- version: 1.8.3
64
+ version: 2.3.3
24
65
  version:
25
- description: Load Objects from Ruby files without having to use YAML or define classes named like the file.
66
+ description: |-
67
+ Load Objects from Ruby files without having to use YAML or define
68
+ classes named like the file.
26
69
  email:
27
70
  - postmodern.mod3@gmail.com
28
71
  executables: []
@@ -48,11 +91,19 @@ files:
48
91
  - lib/contextify/pending_context.rb
49
92
  - lib/contextify/contextify.rb
50
93
  - lib/contextify/version.rb
94
+ - lib/contextify/yard.rb
95
+ - lib/contextify/yard/handlers.rb
96
+ - lib/contextify/yard/handlers/ruby.rb
97
+ - lib/contextify/yard/handlers/ruby/contextify_handler.rb
98
+ - lib/contextify/yard/handlers/ruby/legacy.rb
99
+ - lib/contextify/yard/handlers/ruby/legacy/contextify_handler.rb
51
100
  - spec/contextify_spec.rb
52
101
  - spec/spec_helper.rb
53
102
  - tasks/spec.rb
54
- has_rdoc: true
103
+ has_rdoc: yard
55
104
  homepage: http://contextify.rubyforge.org/
105
+ licenses: []
106
+
56
107
  post_install_message:
57
108
  rdoc_options:
58
109
  - --main
@@ -74,9 +125,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
125
  requirements: []
75
126
 
76
127
  rubyforge_project: contextify
77
- rubygems_version: 1.3.1
128
+ rubygems_version: 1.3.5
78
129
  signing_key:
79
- specification_version: 2
130
+ specification_version: 3
80
131
  summary: Load Objects from Ruby files without having to use YAML or define classes named like the file.
81
132
  test_files: []
82
133
 
Binary file