Class: Rivet::OpenState
- Inherits:
-
Object
- Object
- Rivet::OpenState
- Defined in:
- lib/rivet/open_state.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#generated_attributes ⇒ Object
readonly
Returns the value of attribute generated_attributes.
-
#required_fields ⇒ Object
Returns the value of attribute required_fields.
Instance Method Summary collapse
-
#initialize ⇒ OpenState
constructor
A new instance of OpenState.
- #install_get_or_set(name) ⇒ Object
- #method_missing(m, *args, &block) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize ⇒ OpenState
Returns a new instance of OpenState.
8 9 10 |
# File 'lib/rivet/open_state.rb', line 8 def initialize @generated_attributes = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/rivet/open_state.rb', line 35 def method_missing(m, *args, &block) if args.size < 1 super else install_get_or_set(m) send(m, args[0]) end end |
Instance Attribute Details
#generated_attributes ⇒ Object (readonly)
Returns the value of attribute generated_attributes.
5 6 7 |
# File 'lib/rivet/open_state.rb', line 5 def generated_attributes @generated_attributes end |
#required_fields ⇒ Object
Returns the value of attribute required_fields.
6 7 8 |
# File 'lib/rivet/open_state.rb', line 6 def required_fields @required_fields end |
Instance Method Details
#install_get_or_set(name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rivet/open_state.rb', line 12 def install_get_or_set(name) @generated_attributes << name define_singleton_method(name) do |*args| if args.size < 1 instance_variable_get("@#{name}") else instance_variable_set("@#{name}", args[0]) end end end |
#validate ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rivet/open_state.rb', line 23 def validate required_fields.each_pair do |method, default_value| unless respond_to?(method) if default_value.nil? fail "Required field #{method} missing!" else send(method, default_value) end end end end |