Class: Rectify::StubForm

Inherits:
Object
  • Object
show all
Defined in:
lib/rectify/rspec/stub_form.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ StubForm

Returns a new instance of StubForm.



3
4
5
# File 'lib/rectify/rspec/stub_form.rb', line 3

def initialize(attributes)
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/rectify/rspec/stub_form.rb', line 19

def method_missing(method_name, *args, &block)
  if attributes.key?(method_name)
    attributes[method_name]
  elsif method_name.to_s.ends_with?("=")
    attribute_name = method_name.to_s.chomp("=").to_sym
    attributes[attribute_name] = args.first
  else
    super
  end
end

Instance Method Details

#attributesObject



7
8
9
# File 'lib/rectify/rspec/stub_form.rb', line 7

def attributes
  @attributes.except!(:valid?)
end

#invalid?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rectify/rspec/stub_form.rb', line 15

def invalid?
  !valid?
end

#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/rectify/rspec/stub_form.rb', line 30

def respond_to_missing?(method_name, _include_private = false)
  attributes.key?(method_name)
end

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/rectify/rspec/stub_form.rb', line 11

def valid?
  @attributes.fetch(:valid?, false)
end