Module: Stickler::Middleware::Helpers::Specs
- Included in:
- Index
- Defined in:
- lib/stickler/middleware/helpers.rb
Overview
Manage the contents of the stickler.specs environment variable. It is used as as communcation method between the various types of middlewares managing gem repositories. The Index server will use the values in this variable in generating the responses to gem index requests
env is a Hash itself, the key being the return value of root_dir from the Class it is included in, the value for each key is the Array of SpecLite’s.
Instance Method Summary collapse
-
#append_latest_specs ⇒ Object
Automatically append the latest_specs from the included class into the specs environment variable.
-
#append_spec(key, spec_or_array_of_specs) ⇒ Object
Append spec or array of specs to the current list of specs for this key.
-
#append_specs ⇒ Object
Automatically append the specs from the included class into the specs environment variable.
-
#specs ⇒ Object
return the flattened array of all the values in
#specs_by_repo. -
#specs_by_first_upcase_char ⇒ Object
Return all the specs as a hash of specs_by_name.
-
#specs_by_name ⇒ Object
return the specs as a hash of lists, keyedy by gemname.
-
#specs_by_repo ⇒ Object
The specs by repository.
-
#specs_grouped_by_name(list) ⇒ Object
Given a list of specs, this will group them by name.
Instance Method Details
#append_latest_specs ⇒ Object
Automatically append the latest_specs from the included class into the specs environment variable.
The Class that includes this module and wants to use append_specs MUST have a repo method. The repo method must respond_to both root_dir and specs.
111 112 113 |
# File 'lib/stickler/middleware/helpers.rb', line 111 def append_latest_specs append_spec( self.repo.root_dir, self.repo.latest_specs ) end |
#append_spec(key, spec_or_array_of_specs) ⇒ Object
Append spec or array of specs to the current list of specs for this key.
83 84 85 86 87 88 89 |
# File 'lib/stickler/middleware/helpers.rb', line 83 def append_spec( key, spec_or_array_of_specs ) if Array === spec_or_array_of_specs then specs_by_repo[key].concat( spec_or_array_of_specs ) else specs_by_repo[key] << spec_or_array_of_specs end end |
#append_specs ⇒ Object
Automatically append the specs from the included class into the specs environment variable.
The Class that includes this module and wants to use append_specs MUST have a repo method. The repo method must respond_to both root_dir and specs.
99 100 101 |
# File 'lib/stickler/middleware/helpers.rb', line 99 def append_specs append_spec( self.repo.root_dir, self.repo.specs ) end |
#specs ⇒ Object
return the flattened array of all the values in #specs_by_repo
44 45 46 |
# File 'lib/stickler/middleware/helpers.rb', line 44 def specs [ specs_by_repo.values ].flatten.sort end |
#specs_by_first_upcase_char ⇒ Object
Return all the specs as a hash of specs_by_name. The keys in this case are the first character of the gem name
59 60 61 62 63 64 65 66 67 |
# File 'lib/stickler/middleware/helpers.rb', line 59 def specs_by_first_upcase_char by_char = Hash.new{ |h,k| h[k] = Array.new } specs.each do |spec| by_char[spec.name[0...1].upcase] << spec end by_char.keys.each { |k| by_char[k] = specs_grouped_by_name(by_char[k]) } return by_char end |
#specs_by_name ⇒ Object
return the specs as a hash of lists, keyedy by gemname
51 52 53 |
# File 'lib/stickler/middleware/helpers.rb', line 51 def specs_by_name specs_grouped_by_name( specs ) end |
#specs_by_repo ⇒ Object
The specs by repository
36 37 38 |
# File 'lib/stickler/middleware/helpers.rb', line 36 def specs_by_repo env['stickler.specs'] ||= Hash.new{ |h,k| h[k] = Array.new } end |
#specs_grouped_by_name(list) ⇒ Object
Given a list of specs, this will group them by name
72 73 74 75 76 77 78 |
# File 'lib/stickler/middleware/helpers.rb', line 72 def specs_grouped_by_name( list ) by_name = Hash.new{ |h,k| h[k] = Array.new } list.each do |spec| by_name[spec.name.downcase] << spec end return by_name end |