Class: Main::Parameter::DSL

Inherits:
Object show all
Defined in:
lib/main/parameter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(param) ⇒ DSL

Returns a new instance of DSL.



570
571
572
# File 'lib/main/parameter.rb', line 570

def initialize param
  @param = param
end

Instance Attribute Details

#paramObject (readonly)

Returns the value of attribute param.



568
569
570
# File 'lib/main/parameter.rb', line 568

def param
  @param
end

Class Method Details

.evaluate(param, &block) ⇒ Object



564
565
566
# File 'lib/main/parameter.rb', line 564

def self.evaluate param, &block
  new(param).instance_eval(&block)
end

Instance Method Details

#argument(arg) ⇒ Object



610
611
612
# File 'lib/main/parameter.rb', line 610

def argument arg 
  param.argument arg 
end

#argument_optional(bool = true) ⇒ Object



624
625
626
627
628
629
630
# File 'lib/main/parameter.rb', line 624

def argument_optional bool = true
  if bool
    param.argument :optional
  else
    param.argument false 
  end
end

#argument_optional?Boolean

Returns:

  • (Boolean)


631
632
633
# File 'lib/main/parameter.rb', line 631

def argument_optional?
  param.argument_optional?
end

#argument_required(bool = true) ⇒ Object



613
614
615
616
617
618
619
# File 'lib/main/parameter.rb', line 613

def argument_required bool = true
  if bool
    param.argument :required
  else
    param.argument false 
  end
end

#argument_required?Boolean

Returns:

  • (Boolean)


620
621
622
# File 'lib/main/parameter.rb', line 620

def argument_required?
  param.argument_required?
end

#arity(value) ⇒ Object

Raises:



692
693
694
695
696
697
698
699
700
701
702
# File 'lib/main/parameter.rb', line 692

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

Returns:

  • (Boolean)


703
704
705
# File 'lib/main/parameter.rb', line 703

def arity?
  param.arity?
end

#attr(*a, &b) ⇒ Object



587
588
589
# File 'lib/main/parameter.rb', line 587

def attr(*a, &b)
  fattr(*a, &b)
end

#cast(sym = nil, &b) ⇒ Object



653
654
655
# File 'lib/main/parameter.rb', line 653

def cast sym=nil, &b 
  param.cast = sym || b 
end

#cast?Boolean

Returns:

  • (Boolean)


656
657
658
# File 'lib/main/parameter.rb', line 656

def cast?
  param.cast?
end

#default(*values, &block) ⇒ Object Also known as: defaults



675
676
677
678
679
680
681
682
683
684
685
686
# File 'lib/main/parameter.rb', line 675

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

Returns:

  • (Boolean)


688
689
690
# File 'lib/main/parameter.rb', line 688

def defaults?
  param.defaults?
end

#description(s) ⇒ Object Also known as: desc



667
668
669
# File 'lib/main/parameter.rb', line 667

def description s 
  param.description = s.to_s
end

#description?Boolean

Returns:

  • (Boolean)


670
671
672
# File 'lib/main/parameter.rb', line 670

def description?
  param.description?
end

#error(which = :instead, &block) ⇒ Object



707
708
709
# File 'lib/main/parameter.rb', line 707

def error which = :instead, &block
  param.send "error_handler_#{ which }=", block
end

#example(*list) ⇒ Object Also known as: examples



591
592
593
594
595
# File 'lib/main/parameter.rb', line 591

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



574
575
576
577
578
579
# File 'lib/main/parameter.rb', line 574

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



582
583
584
585
# File 'lib/main/parameter.rb', line 582

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



642
643
644
645
646
647
648
# File 'lib/main/parameter.rb', line 642

def optional bool = true 
  if bool 
    param.required !bool  
  else
    param.required bool  
  end
end

#optional?Boolean

Returns:

  • (Boolean)


649
650
651
# File 'lib/main/parameter.rb', line 649

def optional?
  param.optional?
end

#required(bool = true) ⇒ Object



635
636
637
# File 'lib/main/parameter.rb', line 635

def required bool = true 
  param.required = bool 
end

#required?Boolean

Returns:

  • (Boolean)


638
639
640
# File 'lib/main/parameter.rb', line 638

def required?
  param.required?
end

#synopsis(*arg) ⇒ Object



606
607
608
# File 'lib/main/parameter.rb', line 606

def synopsis *arg 
  arg.size == 0 ? param.synopsis : (param.synopsis arg.first)
end

#type(*sym) ⇒ Object



599
600
601
# File 'lib/main/parameter.rb', line 599

def type *sym
  sym.size == 0 ? param.type : (param.type = sym.first)
end

#type?Boolean

Returns:

  • (Boolean)


602
603
604
# File 'lib/main/parameter.rb', line 602

def type?
  param.type?
end

#validate(sym = nil, &b) ⇒ Object



660
661
662
# File 'lib/main/parameter.rb', line 660

def validate sym=nil, &b 
  param.validate = sym || b 
end

#validate?Boolean

Returns:

  • (Boolean)


663
664
665
# File 'lib/main/parameter.rb', line 663

def validate?
  param.validate?
end