Module: Ridley::DSL

Included in:
Connection
Defined in:
lib/ridley/dsl.rb,
lib/ridley/resources/node.rb,
lib/ridley/resources/role.rb,
lib/ridley/resources/client.rb,
lib/ridley/resources/search.rb,
lib/ridley/resources/sandbox.rb,
lib/ridley/resources/cookbook.rb,
lib/ridley/resources/data_bag.rb,
lib/ridley/resources/environment.rb

Overview

A DSL to be included into Ridley::Connection. Instance functions of the same name as Chef a resource are coerced into class functions of a class of the same name.

This is accomplished by returning a Ridley::Context object and coercing any messages sent to it into a message to the Chef resource’s class in Ridley.

Examples:

class Connection
  include Ridley::DSL
end

connection = Ridley::Connection.new
connection.role.all

The 'role' function is made available to the instance of Ridley::Connection by including
Ridley::DSL. This function returns a Ridley::Context object which receives the 'all' message.
The Ridley::Context coerces the 'all' message into a message to the Ridley::Role class and
sends along the instance of Ridley::Connection that is chaining 'role.all'

connection.role.all => Ridley::Role.all(connection)

Any additional arguments will also be passed to the class function of the Chef resource's class

connection.role.find("reset") => Ridley::Role.find(connection, "reset")

instantiating new resources

class connection
  include Ridley::DSL
end

connection = Ridley::Connection.new
connection.role.new(name: "hello") => <#Ridley::Role: @name="hello">

New instances of resources can be instantiated by calling new on the Ridley::Context. These messages
will be send to the Chef resource's class in Ridley and can be treated as a normal Ruby object. Each
instantiated object will have the connection information contained within so you can do things like
save a role after changing it's attributes.

r = connection.role.new(name: "new-role")
r.name => "new-role"
r.name = "other-name"
r.save

connection.role.find("new-role") => <#Ridley::Role: @name="new-role">

See Also:

Author:

Instance Method Summary collapse

Instance Method Details

#clientRidley::Context

Coerces instance functions into class functions on Ridley::Client. This coercion sends an instance of the including class along to the class function.

Returns:

  • (Ridley::Context)

    a context object to delegate instance functions to class functions on Ridley::Client

See Also:



71
72
73
# File 'lib/ridley/resources/client.rb', line 71

def client
  Context.new(Ridley::Client, self)
end

#cookbookRidley::Context

Coerces instance functions into class functions on Ridley::Cookbook. This coercion sends an instance of the including class along to the class function.

Returns:

  • (Ridley::Context)

    a context object to delegate instance functions to class functions on Ridley::Cookbook

See Also:



49
50
51
# File 'lib/ridley/resources/cookbook.rb', line 49

def cookbook
  Context.new(Ridley::Cookbook, self)
end

#data_bagRidley::Context

Coerces instance functions into class functions on Ridley::DataBag. This coercion sends an instance of the including class along to the class function.

Returns:

  • (Ridley::Context)

    a context object to delegate instance functions to class functions on Ridley::DataBag

See Also:



71
72
73
# File 'lib/ridley/resources/data_bag.rb', line 71

def data_bag
  Context.new(Ridley::DataBag, self)
end

#environmentRidley::Context

Coerces instance functions into class functions on Ridley::Environment. This coercion sends an instance of the including class along to the class function.

Returns:

  • (Ridley::Context)

    a context object to delegate instance functions to class functions on Ridley::Environment

See Also:



91
92
93
# File 'lib/ridley/resources/environment.rb', line 91

def environment
  Context.new(Ridley::Environment, self)
end

#nodeRidley::Context

Coerces instance functions into class functions on Ridley::Node. This coercion sends an instance of the including class along to the class function.

Returns:

  • (Ridley::Context)

    a context object to delegate instance functions to class functions on Ridley::Node

See Also:



145
146
147
# File 'lib/ridley/resources/node.rb', line 145

def node
  Context.new(Ridley::Node, self)
end

#roleRidley::Context

Coerces instance functions into class functions on Ridley::Role. This coercion sends an instance of the including class along to the class function.

Returns:

  • (Ridley::Context)

    a context object to delegate instance functions to class functions on Ridley::Role

See Also:



75
76
77
# File 'lib/ridley/resources/role.rb', line 75

def role
  Context.new(Ridley::Role, self)
end

#sandboxRidley::Context

Coerces instance functions into class functions on Ridley::Sandbox. This coercion sends an instance of the including class along to the class function.

Returns:

  • (Ridley::Context)

    a context object to delegate instance functions to class functions on Ridley::Sandbox

See Also:



118
119
120
# File 'lib/ridley/resources/sandbox.rb', line 118

def sandbox
  Context.new(Ridley::Sandbox, self)
end

#search(index, query = nil, options = {}) ⇒ Hash

Creates an runs a new Ridley::Search

Parameters:

  • index (String, Symbol)
  • query (String, nil) (defaults to: nil)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :sort (String)
  • :rows (Integer)
  • :start (Integer)

Returns:

  • (Hash)

See Also:



116
117
118
# File 'lib/ridley/resources/search.rb', line 116

def search(index, query = nil, options = {})
  Search.new(self, index, query, options).run
end

#search_indexesArray<Symbol, String>

Return the array of all possible search indexes for the including connection

Examples:

conn = Ridley.connection(...)
conn.search_indexes => 
  [:client, :environment, :node, :role, :"ridley-two", :"ridley-one"]

Returns:

  • (Array<Symbol, String>)


128
129
130
# File 'lib/ridley/resources/search.rb', line 128

def search_indexes
  Search.indexes(self)
end