Class: ActionService::Struct
- Inherits:
-
Object
- Object
- ActionService::Struct
- Defined in:
- lib/action_service/struct.rb
Overview
To send structured types across the wire, derive from ActionService::Struct, and use member
to declare structure members.
Example
class Person < ActionService::Struct
member :firstnames, [String]
member :lastname, String
member :email, String
end
Active Record model classes are already implicitly supported for return value signatures. A structure containing its columns as members will be automatically generated if its present in a signature.
Class Method Summary collapse
-
.member(name, type) ⇒ Object
Creates a structure member accessible using
name
. -
.members ⇒ Object
:nodoc:.
Class Method Details
.member(name, type) ⇒ Object
Creates a structure member accessible using name
. Generates accessor methods for reading and writing the member value.
19 20 21 22 23 24 25 |
# File 'lib/action_service/struct.rb', line 19 def self.member(name, type) write_inheritable_hash("struct_members", name => type) class_eval <<-END def #{name}; @#{name}; end def #{name}=(value); @#{name} = value; end END end |
.members ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/action_service/struct.rb', line 27 def self.members # :nodoc: read_inheritable_attribute("struct_members") || {} end |