Skip to content

Instantly share code, notes, and snippets.

@maxlinc
Last active August 29, 2015 14:01
Show Gist options
  • Save maxlinc/19354152adf8555b158a to your computer and use it in GitHub Desktop.
Save maxlinc/19354152adf8555b158a to your computer and use it in GitHub Desktop.
Start of a Hashie::Dash yard extension?
# Usage: `yardoc -e dash_property_handler.rb lib/**/*.rb`
class DashPropertyHandler < YARD::Handlers::Ruby::AttributeHandler
handles method_call(:property)
namespace_only
def process
name = statement.parameters.first.jump(:tstring_literal, :ident).source
scope = :instance
namespace.attributes[scope][name] ||= SymbolHash[:read => nil, :write => nil]
o = YARD::CodeObjects::MethodObject.new(namespace, name)
# add custom metadata to the object
o['custom_field'] = 'Generated by Hashie::Dash'
doc = "Sets the attribute #{name}\n@param value the value to set the attribute #{name} to."
o.docstring = doc if o.docstring.blank?(false)
register(o)
namespace.attributes[:instance][name][:read] = o
namespace.attributes[:instance][name][:write] = o
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment