Module: Only
- Defined in:
- lib/only.rb,
lib/only/version.rb,
lib/only/base_constraint.rb
Defined Under Namespace
Classes: BaseConstraint
Constant Summary collapse
- VERSION =
'0.0.3'
Class Method Summary collapse
-
.allow(options = {}) ⇒ Object
Options: :prefix :suffix.
- .constraints ⇒ Object
- .define(name, &match_proc) ⇒ Object
Class Method Details
.allow(options = {}) ⇒ Object
Options:
:prefix
:suffix
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/only.rb', line 13 def allow( = {}) prefix = .delete :prefix suffix = .delete :suffix # Extract the param attribute name and collection to match against attribute_name, collection = .first # This is the name used for the DSL name = attribute_name.to_s.pluralize name = :"#{prefix}_#{name}" if prefix name = :"#{name}_#{suffix}" if suffix define(name) { collection.include? params[attribute_name] } end |
.constraints ⇒ Object
6 7 8 |
# File 'lib/only.rb', line 6 def constraints @constraints ||= {} end |
.define(name, &match_proc) ⇒ Object
28 29 30 31 |
# File 'lib/only.rb', line 28 def define(name, &match_proc) constraints[name] = Class.new(BaseConstraint) constraints[name].define_singleton_method :condition_matches?, match_proc end |