Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to describe input filters #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/mutations/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def input_filters
end
end

def input_descriptions
input_filters.input_descriptions if input_filters.respond_to?(:input_descriptions)
end

end

# Instance methods
Expand Down
17 changes: 17 additions & 0 deletions lib/mutations/hash_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def self.register_additional_filter(type_class, type_name)
name = args[0]
options = args[1] || {}

if described = current_input_description
@input_descriptions[name.to_sym] = described
end

@current_inputs[name.to_sym] = type_class.new(options, &block)
end
end
Expand All @@ -16,10 +20,13 @@ def self.register_additional_filter(type_class, type_name)
attr_accessor :optional_inputs
attr_accessor :required_inputs

attr_accessor :input_descriptions, :input_description

def initialize(opts = {}, &block)
super(opts)

@optional_inputs = {}
@input_descriptions = {}
@required_inputs = {}
@current_inputs = @required_inputs

Expand All @@ -39,6 +46,16 @@ def dup
dupped
end

def desc input_description
@input_description = input_description
end

def current_input_description
val = @input_description && @input_description.dup
@input_description = nil
val
end

def required(&block)
@current_inputs = @required_inputs
instance_eval &block
Expand Down