Class: Rectify::StubForm
- Inherits:
-
Object
- Object
- Rectify::StubForm
- Defined in:
- lib/rectify/rspec/stub_form.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ StubForm
constructor
A new instance of StubForm.
- #invalid? ⇒ Boolean
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes) ⇒ StubForm
Returns a new instance of StubForm.
5 6 7 8 |
# File 'lib/rectify/rspec/stub_form.rb', line 5 def initialize(attributes) @valid = attributes.fetch(:valid?, false) @attributes = attributes.except!(:valid?) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rectify/rspec/stub_form.rb', line 18 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 Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/rectify/rspec/stub_form.rb', line 3 def attributes @attributes end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
3 4 5 |
# File 'lib/rectify/rspec/stub_form.rb', line 3 def valid @valid end |
Instance Method Details
#invalid? ⇒ Boolean
14 15 16 |
# File 'lib/rectify/rspec/stub_form.rb', line 14 def invalid? !valid? end |
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
29 30 31 |
# File 'lib/rectify/rspec/stub_form.rb', line 29 def respond_to_missing?(method_name, _include_private = false) attributes.key?(method_name) end |
#valid? ⇒ Boolean
10 11 12 |
# File 'lib/rectify/rspec/stub_form.rb', line 10 def valid? valid end |