Class: Cli_Yo::Yo_Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/cli_yo/yo_arguments.rb

Instance Method Summary collapse

Constructor Details

#initialize(arguments = Hash.new) ⇒ Yo_Arguments

Returns a new instance of Yo_Arguments.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/cli_yo/yo_arguments.rb', line 3

def initialize arguments = Hash.new
  @arguments = Hash.new

  Cli_Yo.all_properties.each do |prop|
    @arguments[prop] = arguments[prop]
  end

  @arguments[:times] ||= 1
  @arguments[:api_token] ||= `echo $YO_TOKEN`.chomp
  @arguments[:interval] ||= 1
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cli_yo/yo_arguments.rb', line 15

def method_missing method , *args
  #check whether the property actuall exists

  is_setter = (method.to_s[-1] == '=')
  reference_symbol = method.to_s[-1] == '=' ? method.to_s.chop.to_sym : method
  super unless Cli_Yo.all_properties.include? reference_symbol
  if is_setter
    @arguments[reference_symbol] = args[0]
  else
    @arguments[reference_symbol]
  end
end

Instance Method Details

#property_is_set?(property) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/cli_yo/yo_arguments.rb', line 28

def property_is_set? property
  property = property.to_sym if property.class == String
  @arguments[property] != nil
end