Class: YARD::APIPlugin::Serializer
- Inherits:
-
Serializers::FileSystemSerializer
- Object
- Serializers::FileSystemSerializer
- YARD::APIPlugin::Serializer
- Defined in:
- lib/yard-api/serializer.rb
Constant Summary collapse
- USNSEP =
url-safe namespace separator
'__'- FSSEP =
'/'
Class Method Summary collapse
-
.str_underscore(camel_cased_word) ⇒ Object
Stolen from rails 4.2, see:.
- .topicize(str) ⇒ Object
Instance Method Summary collapse
Class Method Details
.str_underscore(camel_cased_word) ⇒ Object
Stolen from rails 4.2, see:
13 14 15 16 17 18 19 20 21 |
# File 'lib/yard-api/serializer.rb', line 13 def self.str_underscore(camel_cased_word) return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/ word = camel_cased_word.to_s.gsub(/::/, '/') word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word end |
.topicize(str) ⇒ Object
6 7 8 |
# File 'lib/yard-api/serializer.rb', line 6 def self.topicize(str) self.str_underscore(str.lines.first.gsub(/\W+/, '_')) end |
Instance Method Details
#get_api_id(object) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/yard-api/serializer.rb', line 54 def get_api_id(object) if object[:api_id] object.api_id elsif tag = object.tag(:API) tag.text.lines.first.strip else object.to_s end end |
#serialize(object, data) ⇒ Object
23 24 25 26 |
# File 'lib/yard-api/serializer.rb', line 23 def serialize(object, data) path = File.join(basepath, serialized_path(object)) File.open!(path, "wb") {|f| f.write data } end |
#serialized_path(object) ⇒ Object
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 |
# File 'lib/yard-api/serializer.rb', line 28 def serialized_path(object) return object if object.is_a?(String) fspath = nil if object.is_a?(YARD::CodeObjects::ExtraFileObject) fspath = 'file.' + object.name + (extension.empty? ? '' : ".#{extension}") else fspath = if object == YARD::Registry.root "top-level-namespace" else self.class.topicize(get_api_id(object)) end if object.is_a?(YARD::CodeObjects::MethodObject) fspath += '_' + object.scope.to_s[0,1] end unless extension.empty? fspath += ".#{extension}" end end fspath.gsub(/[^\w\.\-_\/]+/, '-') end |