Class: FakeData::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_data/method.rb,
lib/fake_data/method/faker.rb,
lib/fake_data/method/control.rb

Direct Known Subclasses

Control, Faker

Defined Under Namespace

Classes: Control, Faker

Constant Summary collapse

METHOD_MATCHER =

TODO: problem with parsing “test()” => method = test; arguments = [“()”]

/((?<klass>[a-z_.:]+)\.)?(?<method>[a-z0-9_=\?]+)\s*(\((?<args1>.+)\)|(?<args2>.+))?\s*/i
LEFT_BRACKET_MATCHER =
/^\(/
RIGHT_BRACKET_MATCHER =
/\)$/
ARGUMENT_SPLIT_MATCHER =

TODO: better argument splitting does not works with arrays, hash etc method(1, [1, 2])

/\s*,\s*/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Method

Returns a new instance of Method.



16
17
18
19
# File 'lib/fake_data/method.rb', line 16

def initialize raw
  @raw = raw
  @klass, @method, @arguments = parse(@raw)
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



14
15
16
# File 'lib/fake_data/method.rb', line 14

def arguments
  @arguments
end

#klassObject (readonly)

Returns the value of attribute klass.



14
15
16
# File 'lib/fake_data/method.rb', line 14

def klass
  @klass
end

#methodObject (readonly)

Returns the value of attribute method.



14
15
16
# File 'lib/fake_data/method.rb', line 14

def method
  @method
end

#rawObject (readonly)

Returns the value of attribute raw.



14
15
16
# File 'lib/fake_data/method.rb', line 14

def raw
  @raw
end

Instance Method Details

#callObject



25
26
27
# File 'lib/fake_data/method.rb', line 25

def call
  eval(source)
end

#sourceObject



21
22
23
# File 'lib/fake_data/method.rb', line 21

def source
  make_call(klass, method, arguments)
end

#to_sObject



29
30
31
# File 'lib/fake_data/method.rb', line 29

def to_s
  source
end