Module: Seahorse::Model::ClassMethods
- Defined in:
- lib/seahorse/model.rb
Instance Attribute Summary collapse
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
Instance Method Summary collapse
- #add_routes(router) ⇒ Object
- #desc(text) ⇒ Object
- #model_name ⇒ Object
- #operation(name, &block) ⇒ Object
- #operation_from_action(action) ⇒ Object
- #to_hash ⇒ Object
- #type(name, &block) ⇒ Object
Instance Attribute Details
#operations ⇒ Object (readonly)
Returns the value of attribute operations.
21 22 23 |
# File 'lib/seahorse/model.rb', line 21 def operations @operations end |
Instance Method Details
#add_routes(router) ⇒ Object
27 28 29 |
# File 'lib/seahorse/model.rb', line 27 def add_routes(router) Seahorse::Router.new(self).add_routes(router) end |
#desc(text) ⇒ Object
31 32 33 |
# File 'lib/seahorse/model.rb', line 31 def desc(text) @desc = text end |
#model_name ⇒ Object
23 24 25 |
# File 'lib/seahorse/model.rb', line 23 def model_name name.underscore.gsub(/_api$|^api\//, '') end |
#operation(name, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/seahorse/model.rb', line 35 def operation(name, &block) name, action = *operation_name_and_action(name) @actions ||= {} @operations ||= {} @operations[name] = Operation.new(self, name, action, &block) @operations[name].documentation = @desc @actions[action] = @operations[name] @desc = nil end |
#operation_from_action(action) ⇒ Object
45 46 47 48 |
# File 'lib/seahorse/model.rb', line 45 def operation_from_action(action) @actions ||= {} @actions[action] end |
#to_hash ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/seahorse/model.rb', line 56 def to_hash ops = @operations.inject({}) do |hash, (name, operation)| hash[name.camelcase(:lower)] = operation.to_hash hash end {'operations' => ops} end |
#type(name, &block) ⇒ Object
50 51 52 53 54 |
# File 'lib/seahorse/model.rb', line 50 def type(name, &block) supertype = 'structure' name, supertype = *name.map {|k,v| [k, v] }.flatten if Hash === name ShapeBuilder.type(name, supertype, &block) end |