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.
537 538 539 |
# File 'lib/main/parameter.rb', line 537 def initialize param @param = param end |
Instance Attribute Details
#param ⇒ Object (readonly)
Returns the value of attribute param.
534 535 536 |
# File 'lib/main/parameter.rb', line 534 def param @param end |
Class Method Details
.evaluate(param, &block) ⇒ Object
530 531 532 |
# File 'lib/main/parameter.rb', line 530 def self.evaluate param, &block new(param).evaluate(&block) end |
Instance Method Details
#argument(arg) ⇒ Object
577 578 579 |
# File 'lib/main/parameter.rb', line 577 def argument arg param.argument arg end |
#argument_optional(bool = true) ⇒ Object
591 592 593 594 595 596 597 |
# File 'lib/main/parameter.rb', line 591 def argument_optional bool = true if bool param.argument :optional else param.argument false end end |
#argument_optional? ⇒ Boolean
598 599 600 |
# File 'lib/main/parameter.rb', line 598 def argument_optional? param.argument_optional? end |
#argument_required(bool = true) ⇒ Object
580 581 582 583 584 585 586 |
# File 'lib/main/parameter.rb', line 580 def argument_required bool = true if bool param.argument :required else param.argument false end end |
#argument_required? ⇒ Boolean
587 588 589 |
# File 'lib/main/parameter.rb', line 587 def argument_required? param.argument_required? end |
#arity(value) ⇒ Object
659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/main/parameter.rb', line 659 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
670 671 672 |
# File 'lib/main/parameter.rb', line 670 def arity? param.arity? end |
#attr(*a, &b) ⇒ Object
554 555 556 |
# File 'lib/main/parameter.rb', line 554 def attr *a, &b fattr *a, &b end |
#cast(sym = nil, &b) ⇒ Object
620 621 622 |
# File 'lib/main/parameter.rb', line 620 def cast sym=nil, &b param.cast = sym || b end |
#cast? ⇒ Boolean
623 624 625 |
# File 'lib/main/parameter.rb', line 623 def cast? param.cast? end |
#default(*values, &block) ⇒ Object Also known as: defaults
642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/main/parameter.rb', line 642 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
655 656 657 |
# File 'lib/main/parameter.rb', line 655 def defaults? param.defaults? end |
#description(s) ⇒ Object Also known as: desc
634 635 636 |
# File 'lib/main/parameter.rb', line 634 def description s param.description = s.to_s end |
#description? ⇒ Boolean
637 638 639 |
# File 'lib/main/parameter.rb', line 637 def description? param.description? end |
#error(which = :instead, &block) ⇒ Object
674 675 676 |
# File 'lib/main/parameter.rb', line 674 def error which = :instead, &block param.send "error_handler_#{ which }=", block end |
#example(*list) ⇒ Object Also known as: examples
558 559 560 561 562 |
# File 'lib/main/parameter.rb', line 558 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
541 542 543 544 545 546 |
# File 'lib/main/parameter.rb', line 541 def fattr a = nil, &block name = param.name a ||= name b = fattr_block_for name, &block Main.current.module_eval{ fattr *a, &b } end |
#fattr_block_for(name, &block) ⇒ Object
549 550 551 552 |
# File 'lib/main/parameter.rb', line 549 def fattr_block_for name, &block block ||= lambda{|param| [0,1].include?(param.arity) ? param.value : param.values } lambda{ block.call self.param[name] } end |
#optional(bool = true) ⇒ Object
609 610 611 612 613 614 615 |
# File 'lib/main/parameter.rb', line 609 def optional bool = true if bool param.required !bool else param.required bool end end |
#optional? ⇒ Boolean
616 617 618 |
# File 'lib/main/parameter.rb', line 616 def optional? param.optional? end |
#required(bool = true) ⇒ Object
602 603 604 |
# File 'lib/main/parameter.rb', line 602 def required bool = true param.required = bool end |
#required? ⇒ Boolean
605 606 607 |
# File 'lib/main/parameter.rb', line 605 def required? param.required? end |
#synopsis(*arg) ⇒ Object
573 574 575 |
# File 'lib/main/parameter.rb', line 573 def synopsis *arg arg.size == 0 ? param.synopsis : (param.synopsis arg.first) end |
#type(*sym) ⇒ Object
566 567 568 |
# File 'lib/main/parameter.rb', line 566 def type *sym sym.size == 0 ? param.type : (param.type = sym.first) end |
#type? ⇒ Boolean
569 570 571 |
# File 'lib/main/parameter.rb', line 569 def type? param.type? end |
#validate(sym = nil, &b) ⇒ Object
627 628 629 |
# File 'lib/main/parameter.rb', line 627 def validate sym=nil, &b param.validate = sym || b end |
#validate? ⇒ Boolean
630 631 632 |
# File 'lib/main/parameter.rb', line 630 def validate? param.validate? end |