Class: Main::Parameter::DSL
Instance Attribute Summary (collapse)
-
- (Object) param
readonly
Returns the value of attribute param.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) argument(arg)
- - (Object) argument_optional(bool = true)
- - (Boolean) argument_optional?
- - (Object) argument_required(bool = true)
- - (Boolean) argument_required?
- - (Object) arity(value)
- - (Boolean) arity?
- - (Object) attr(*a, &b)
- - (Object) cast(sym = nil, &b)
- - (Boolean) cast?
- - (Object) default(*values, &block) (also: #defaults)
- - (Boolean) defaults?
- - (Object) description(s) (also: #desc)
- - (Boolean) description?
- - (Object) error(which = :instead, &block)
- - (Object) example(*list) (also: #examples)
- - (Object) fattr(a = nil, &block) (also: #attribute)
- - (Object) fattr_block_for(name, &block)
-
- (DSL) initialize(param)
constructor
A new instance of DSL.
- - (Object) optional(bool = true)
- - (Boolean) optional?
- - (Object) required(bool = true)
- - (Boolean) required?
- - (Object) synopsis(*arg)
- - (Object) type(*sym)
- - (Boolean) type?
- - (Object) validate(sym = nil, &b)
- - (Boolean) validate?
Constructor Details
- (DSL) initialize(param)
A new instance of DSL
560 561 562 |
# File 'lib/main/parameter.rb', line 560 def initialize param @param = param end |
Instance Attribute Details
- (Object) param (readonly)
Returns the value of attribute param
558 559 560 |
# File 'lib/main/parameter.rb', line 558 def param @param end |
Class Method Details
+ (Object) evaluate(param, &block)
554 555 556 |
# File 'lib/main/parameter.rb', line 554 def self.evaluate param, &block new(param).instance_eval(&block) end |
Instance Method Details
- (Object) argument(arg)
600 601 602 |
# File 'lib/main/parameter.rb', line 600 def argument arg param.argument arg end |
- (Object) argument_optional(bool = true)
614 615 616 617 618 619 620 |
# File 'lib/main/parameter.rb', line 614 def argument_optional bool = true if bool param.argument :optional else param.argument false end end |
- (Boolean) argument_optional?
621 622 623 |
# File 'lib/main/parameter.rb', line 621 def argument_optional? param.argument_optional? end |
- (Object) argument_required(bool = true)
603 604 605 606 607 608 609 |
# File 'lib/main/parameter.rb', line 603 def argument_required bool = true if bool param.argument :required else param.argument false end end |
- (Boolean) argument_required?
610 611 612 |
# File 'lib/main/parameter.rb', line 610 def argument_required? param.argument_required? end |
- (Object) arity(value)
682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/main/parameter.rb', line 682 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 |
- (Boolean) arity?
693 694 695 |
# File 'lib/main/parameter.rb', line 693 def arity? param.arity? end |
- (Object) attr(*a, &b)
577 578 579 |
# File 'lib/main/parameter.rb', line 577 def attr(*a, &b) fattr(*a, &b) end |
- (Object) cast(sym = nil, &b)
643 644 645 |
# File 'lib/main/parameter.rb', line 643 def cast sym=nil, &b param.cast = sym || b end |
- (Boolean) cast?
646 647 648 |
# File 'lib/main/parameter.rb', line 646 def cast? param.cast? end |
- (Object) default(*values, &block) Also known as: defaults
665 666 667 668 669 670 671 672 673 674 675 676 |
# File 'lib/main/parameter.rb', line 665 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 |
- (Boolean) defaults?
678 679 680 |
# File 'lib/main/parameter.rb', line 678 def defaults? param.defaults? end |
- (Object) description(s) Also known as: desc
657 658 659 |
# File 'lib/main/parameter.rb', line 657 def description s param.description = s.to_s end |
- (Boolean) description?
660 661 662 |
# File 'lib/main/parameter.rb', line 660 def description? param.description? end |
- (Object) error(which = :instead, &block)
697 698 699 |
# File 'lib/main/parameter.rb', line 697 def error which = :instead, &block param.send "error_handler_#{ which }=", block end |
- (Object) example(*list) Also known as: examples
581 582 583 584 585 |
# File 'lib/main/parameter.rb', line 581 def example *list list.flatten.compact.each do |elem| param.examples << elem.to_s end end |
- (Object) fattr(a = nil, &block) Also known as: attribute
564 565 566 567 568 569 |
# File 'lib/main/parameter.rb', line 564 def fattr a = nil, &block name = param.name a ||= name b = fattr_block_for name, &block @param.main.module_eval{ fattr(*a, &b) } end |
- (Object) fattr_block_for(name, &block)
572 573 574 575 |
# File 'lib/main/parameter.rb', line 572 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 |
- (Object) optional(bool = true)
632 633 634 635 636 637 638 |
# File 'lib/main/parameter.rb', line 632 def optional bool = true if bool param.required !bool else param.required bool end end |
- (Boolean) optional?
639 640 641 |
# File 'lib/main/parameter.rb', line 639 def optional? param.optional? end |
- (Object) required(bool = true)
625 626 627 |
# File 'lib/main/parameter.rb', line 625 def required bool = true param.required = bool end |
- (Boolean) required?
628 629 630 |
# File 'lib/main/parameter.rb', line 628 def required? param.required? end |
- (Object) synopsis(*arg)
596 597 598 |
# File 'lib/main/parameter.rb', line 596 def synopsis *arg arg.size == 0 ? param.synopsis : (param.synopsis arg.first) end |
- (Object) type(*sym)
589 590 591 |
# File 'lib/main/parameter.rb', line 589 def type *sym sym.size == 0 ? param.type : (param.type = sym.first) end |
- (Boolean) type?
592 593 594 |
# File 'lib/main/parameter.rb', line 592 def type? param.type? end |
- (Object) validate(sym = nil, &b)
650 651 652 |
# File 'lib/main/parameter.rb', line 650 def validate sym=nil, &b param.validate = sym || b end |
- (Boolean) validate?
653 654 655 |
# File 'lib/main/parameter.rb', line 653 def validate? param.validate? end |