Class: Grape::Hal::Endpoint
- Inherits:
-
Object
- Object
- Grape::Hal::Endpoint
- Includes:
- Dsl
- Defined in:
- lib/grape/hal/endpoint.rb
Instance Attribute Summary collapse
-
#context_path ⇒ Object
readonly
Returns the value of attribute context_path.
-
#current_api ⇒ Object
readonly
Returns the value of attribute current_api.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #generate_hal(base_path) ⇒ Object
- #hal_for(path, options = {}, &block) ⇒ Object
-
#initialize(current_api, context_path) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #mount(api) ⇒ Object
Constructor Details
#initialize(current_api, context_path) ⇒ Endpoint
Returns a new instance of Endpoint.
9 10 11 12 13 14 |
# File 'lib/grape/hal/endpoint.rb', line 9 def initialize(current_api, context_path) @current_api = current_api @context_path = context_path @entries = [] add_self end |
Instance Attribute Details
#context_path ⇒ Object (readonly)
Returns the value of attribute context_path.
7 8 9 |
# File 'lib/grape/hal/endpoint.rb', line 7 def context_path @context_path end |
#current_api ⇒ Object (readonly)
Returns the value of attribute current_api.
7 8 9 |
# File 'lib/grape/hal/endpoint.rb', line 7 def current_api @current_api end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
7 8 9 |
# File 'lib/grape/hal/endpoint.rb', line 7 def entries @entries end |
Instance Method Details
#generate_hal(base_path) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/grape/hal/endpoint.rb', line 38 def generate_hal(base_path) hal_array = entries.map do |entry| key = entry[:rel] || entry[:path] value = {href: get_full_path(base_path, entry)} value[:title] = entry[:title] if entry[:title] value[:templated] = true if is_templated?(entry) [key, value] end {:_links => Hash[hal_array]} end |
#hal_for(path, options = {}, &block) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/grape/hal/endpoint.rb', line 16 def hal_for(path, = {}, &block) entries << { path: path, rel: [:rel], title: [:title] } current_api.hal_for path, &block end |
#mount(api) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/grape/hal/endpoint.rb', line 25 def mount(api) api.endpoints.each do |endpoint| = endpoint. [:path].each do |path| entries << { path: path, rel: [:route_options][:rel], title: [:route_options][:description] } end end end |