Class: Hanami::Routing::Resource::Options Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/routing/resource/options.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Options for RESTFul resource(s)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actions, options = {}) ⇒ Options

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the options for:

* Hanami::Router#resource
* Hanami::Router#resources

Examples:

require 'hanami/router'

Hanami::Router.new do
  resources 'articles', only:   [:index]
  resource  'profile',  except: [:new, :create, :destroy]
end

Parameters:

  • actions (Array<Symbol>)

    the name of the actions

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :only (Hash)

    white list of the default actions

  • :except (Hash)

    black list of the default actions

  • :controller (String)

    namespace for an actions

See Also:

Since:

  • 0.1.0



39
40
41
42
43
44
45
# File 'lib/hanami/routing/resource/options.rb', line 39

def initialize(actions, options = {})
  only     = Array(options.delete(:only) || actions)
  except   = Array(options.delete(:except))
  @actions = ( actions & only ) - except

  @options = options
end

Instance Attribute Details

#actionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



14
15
16
# File 'lib/hanami/routing/resource/options.rb', line 14

def actions
  @actions
end

Instance Method Details

#[](key) ⇒ Object?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the option for the given key

Parameters:

  • key (Symbol)

    the key that should be searched

Returns:

  • (Object, nil)

    returns the object associated to the given key or nil, if missing.

Since:

  • 0.1.1



56
57
58
# File 'lib/hanami/routing/resource/options.rb', line 56

def [](key)
  @options[key]
end

#merge(hash) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Merge the current options with the given hash, without mutating self.

Parameters:

  • hash (Hash)

    the hash to be merged

Returns:

  • (Hash)

    the result of the merging operation

Since:

  • 0.1.1



68
69
70
# File 'lib/hanami/routing/resource/options.rb', line 68

def merge(hash)
  @options.merge(hash)
end