Class: Main::Parameter::DSL
Instance Attribute Summary collapse
-
#param ⇒ Object
readonly
Returns the value of attribute param.
Class Method Summary collapse
Instance Method Summary collapse
- #argument(arg) ⇒ Object
- #argument_optional(bool = true) ⇒ Object
- #argument_optional? ⇒ Boolean
- #argument_required(bool = true) ⇒ Object
- #argument_required? ⇒ Boolean
- #arity(value) ⇒ Object
- #arity? ⇒ Boolean
- #attr(*a, &b) ⇒ Object
- #cast(sym = nil, &b) ⇒ Object
- #cast? ⇒ Boolean
- #default(*values, &block) ⇒ Object (also: #defaults)
- #defaults? ⇒ Boolean
- #description(s) ⇒ Object (also: #desc)
- #description? ⇒ Boolean
- #error(which = :instead, &block) ⇒ Object
- #example(*list) ⇒ Object (also: #examples)
- #fattr(a = nil, &block) ⇒ Object (also: #attribute)
- #fattr_block_for(name, &block) ⇒ Object
-
#initialize(param) ⇒ DSL
constructor
A new instance of DSL.
- #optional(bool = true) ⇒ Object
- #optional? ⇒ Boolean
- #required(bool = true) ⇒ Object
- #required? ⇒ Boolean
- #synopsis(*arg) ⇒ Object
- #type(*sym) ⇒ Object
- #type? ⇒ Boolean
- #validate(sym = nil, &b) ⇒ Object
- #validate? ⇒ Boolean
Constructor Details
#initialize(param) ⇒ DSL
Returns a new instance of DSL.
572 573 574 |
# File 'lib/main/parameter.rb', line 572 def initialize param @param = param end |
Instance Attribute Details
#param ⇒ Object (readonly)
Returns the value of attribute param.
570 571 572 |
# File 'lib/main/parameter.rb', line 570 def param @param end |
Class Method Details
.evaluate(param, &block) ⇒ Object
566 567 568 |
# File 'lib/main/parameter.rb', line 566 def self.evaluate param, &block new(param).instance_eval(&block) end |
Instance Method Details
#argument(arg) ⇒ Object
612 613 614 |
# File 'lib/main/parameter.rb', line 612 def argument arg param.argument arg end |
#argument_optional(bool = true) ⇒ Object
626 627 628 629 630 631 632 |
# File 'lib/main/parameter.rb', line 626 def argument_optional bool = true if bool param.argument :optional else param.argument false end end |
#argument_optional? ⇒ Boolean
633 634 635 |
# File 'lib/main/parameter.rb', line 633 def argument_optional? param.argument_optional? end |
#argument_required(bool = true) ⇒ Object
615 616 617 618 619 620 621 |
# File 'lib/main/parameter.rb', line 615 def argument_required bool = true if bool param.argument :required else param.argument false end end |
#argument_required? ⇒ Boolean
622 623 624 |
# File 'lib/main/parameter.rb', line 622 def argument_required? param.argument_required? end |
#arity(value) ⇒ Object
694 695 696 697 698 699 700 701 702 703 704 |
# File 'lib/main/parameter.rb', line 694 def arity value raise Arity if value.nil? value = -1 if value.to_s == '*' value = Integer value raise Arity if value.zero? param.arity = value if param.arity == -1 optional true end value end |
#arity? ⇒ Boolean
705 706 707 |
# File 'lib/main/parameter.rb', line 705 def arity? param.arity? end |
#attr(*a, &b) ⇒ Object
589 590 591 |
# File 'lib/main/parameter.rb', line 589 def attr(*a, &b) fattr(*a, &b) end |
#cast(sym = nil, &b) ⇒ Object
655 656 657 |
# File 'lib/main/parameter.rb', line 655 def cast sym=nil, &b param.cast = sym || b end |
#cast? ⇒ Boolean
658 659 660 |
# File 'lib/main/parameter.rb', line 658 def cast? param.cast? end |
#default(*values, &block) ⇒ Object Also known as: defaults
677 678 679 680 681 682 683 684 685 686 687 688 |
# File 'lib/main/parameter.rb', line 677 def default *values, &block if block.nil? and values.empty? raise ArgumentError, 'no default' end unless values.empty? param.defaults.push(*values) end unless block.nil? param.defaults.push block end param.defaults end |
#defaults? ⇒ Boolean
690 691 692 |
# File 'lib/main/parameter.rb', line 690 def defaults? param.defaults? end |
#description(s) ⇒ Object Also known as: desc
669 670 671 |
# File 'lib/main/parameter.rb', line 669 def description s param.description = s.to_s end |
#description? ⇒ Boolean
672 673 674 |
# File 'lib/main/parameter.rb', line 672 def description? param.description? end |
#error(which = :instead, &block) ⇒ Object
709 710 711 |
# File 'lib/main/parameter.rb', line 709 def error which = :instead, &block param.send "error_handler_#{ which }=", block end |
#example(*list) ⇒ Object Also known as: examples
593 594 595 596 597 |
# File 'lib/main/parameter.rb', line 593 def example *list list.flatten.compact.each do |elem| param.examples << elem.to_s end end |
#fattr(a = nil, &block) ⇒ Object Also known as: attribute
576 577 578 579 580 581 |
# File 'lib/main/parameter.rb', line 576 def fattr a = nil, &block name = param.name a ||= name b = fattr_block_for(name, &block) @param.main.module_eval{ fattr(*a, &b) } end |
#fattr_block_for(name, &block) ⇒ Object
584 585 586 587 |
# File 'lib/main/parameter.rb', line 584 def fattr_block_for name, &block block ||= lambda{|param| [0,1].include?(param.arity) ? param.value : param.values } lambda{|*args| block.call(self.param[name]) } end |
#optional(bool = true) ⇒ Object
644 645 646 647 648 649 650 |
# File 'lib/main/parameter.rb', line 644 def optional bool = true if bool param.required !bool else param.required bool end end |
#optional? ⇒ Boolean
651 652 653 |
# File 'lib/main/parameter.rb', line 651 def optional? param.optional? end |
#required(bool = true) ⇒ Object
637 638 639 |
# File 'lib/main/parameter.rb', line 637 def required bool = true param.required = bool end |
#required? ⇒ Boolean
640 641 642 |
# File 'lib/main/parameter.rb', line 640 def required? param.required? end |
#synopsis(*arg) ⇒ Object
608 609 610 |
# File 'lib/main/parameter.rb', line 608 def synopsis *arg arg.size == 0 ? param.synopsis : (param.synopsis arg.first) end |
#type(*sym) ⇒ Object
601 602 603 |
# File 'lib/main/parameter.rb', line 601 def type *sym sym.size == 0 ? param.type : (param.type = sym.first) end |
#type? ⇒ Boolean
604 605 606 |
# File 'lib/main/parameter.rb', line 604 def type? param.type? end |
#validate(sym = nil, &b) ⇒ Object
662 663 664 |
# File 'lib/main/parameter.rb', line 662 def validate sym=nil, &b param.validate = sym || b end |
#validate? ⇒ Boolean
665 666 667 |
# File 'lib/main/parameter.rb', line 665 def validate? param.validate? end |