code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def to_s
"validate " \
"#{color} " \
"#{var} " \
"#{var_file}"
end | @return [String] the command with flags. | to_s | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command/validate/pre_zero_fifteen_zero.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command/validate/pre_zero_fifteen_zero.rb | Apache-2.0 |
def initialize(arguments:)
self.arguments = arguments
end | #initialize prepares a new instance of the class.
@param arguments [Hash{String=>String}] the arguments.
@return [Kitchen::Terraform::CommandFlag::BackendConfig] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/backend_config.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/backend_config.rb | Apache-2.0 |
def to_s
arguments.map do |key, value|
"-backend-config=\"#{key}=#{value}\""
end.join " "
end | @return [String] the backend configuration flag. | to_s | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/backend_config.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/backend_config.rb | Apache-2.0 |
def initialize(enabled:)
self.enabled = enabled
end | #initialize prepares a new instance of the class.
@param enabled [Boolean] a toggle to enable or disable color.
@return [Kitchen::Terraform::CommandFlag::Color] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/color.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/color.rb | Apache-2.0 |
def initialize(duration:)
self.duration = duration
end | #initialize prepares a new instance of the class.
@param duration [Integer] the duration in seconds.
@return [Kitchen::Terraform::CommandFlag::LockTimeout] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/lock_timeout.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/lock_timeout.rb | Apache-2.0 |
def initialize(pathname:)
self.pathname = pathname.to_s
end | #initialize prepares a new instance of the class.
@param pathname [String] the pathname of the directory.
@return [Kitchen::Terraform::CommandFlag::PluginDir] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/plugin_dir.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/plugin_dir.rb | Apache-2.0 |
def to_s
if pathname.empty?
""
else
"-plugin-dir=\"#{::Shellwords.shelljoin ::Shellwords.shellsplit pathname}\""
end
end | @return [String] the plugin directory flag. | to_s | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/plugin_dir.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/plugin_dir.rb | Apache-2.0 |
def initialize(enabled:)
self.enabled = enabled
end | #initialize prepares a new instance of the class.
@param enabled [Boolean] a toggle to enable or disable the upgrade.
@return [Kitchen::Terraform::CommandFlag::Upgrade] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/upgrade.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/upgrade.rb | Apache-2.0 |
def initialize(arguments:)
self.arguments = arguments
end | #initialize prepares a new instance of the class.
@param arguments [Hash{String=>String}] the arguments.
@return [Kitchen::Terraform::CommandFlag::Var] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/var.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/var.rb | Apache-2.0 |
def to_s
arguments.map do |key, value|
"-var=\"#{key}=#{value}\""
end.join " "
end | @return [String] the backend configuration flag. | to_s | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/var.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/var.rb | Apache-2.0 |
def initialize(pathnames:)
self.pathnames = pathnames
end | #initialize prepares a new instance of the class.
@param pathnames [Array[String]] the pathnames.
@return [Kitchen::Terraform::CommandFlag::VarFile] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/var_file.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/var_file.rb | Apache-2.0 |
def to_s
pathnames.map do |path|
"-var-file=\"#{::Shellwords.shelljoin ::Shellwords.shellsplit path}\""
end.join " "
end | @return [String] the backend configuration flag. | to_s | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/command_flag/var_file.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/command_flag/var_file.rb | Apache-2.0 |
def included(plugin_class)
::Kitchen::Terraform::ConfigAttributeDefiner.new(
attribute: self,
schema: ::Kitchen::Terraform::ConfigAttributeContract::String.new,
).define plugin_class: plugin_class
plugin_class.expand_path_for to_sym do |plugin|
!::TTY::Which.exist? plugin[to_sym]
end
self
end | .included is a callback to define the configuration attribute which is invoked when this module is included
in a plugin class.
@param plugin_class [Kitchen::Configurable] A plugin class.
@return [self] | included | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/config_attribute/client.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute/client.rb | Apache-2.0 |
def doctor_config_client
errors = false
if !::TTY::Which.exist? config_client
errors = true
logger.error "client '#{config_client}' is not executable or does not exist"
end
errors
end | #doctor_config_client validates the client configuration.
@return [Boolean] +true+ if any errors are found; +false+ if no errors are found. | doctor_config_client | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/config_attribute/client.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute/client.rb | Apache-2.0 |
def included(plugin_class)
::Kitchen::Terraform::FilePathConfigAttributeDefiner.new(
attribute: self,
schema: ::Kitchen::Terraform::ConfigAttributeContract::OptionalString.new,
).define plugin_class: plugin_class
end | A callback to define the configuration attribute which is invoked when this module is included in a plugin
class.
@param plugin_class [Kitchen::Configurable] A plugin class.
@return [void] | included | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/config_attribute/plugin_directory.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute/plugin_directory.rb | Apache-2.0 |
def included(plugin_class)
::Kitchen::Terraform::FilePathConfigAttributeDefiner.new(
attribute: self,
schema: ::Kitchen::Terraform::ConfigAttributeContract::String.new,
).define plugin_class: plugin_class
end | A callback to define the configuration attribute which is invoked when this module is included in a plugin
class.
@param plugin_class [Kitchen::Configurable] A plugin class.
@return [void] | included | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/config_attribute/root_module_directory.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute/root_module_directory.rb | Apache-2.0 |
def doctor_config_systems
errors = false
if config_systems.empty?
errors = true
logger.error "systems is empty"
end
errors
end | #doctor_config_systems validates the systems configuration.
@return [Boolean] +true+ if any errors are found; +false+ if no errors are found. | doctor_config_systems | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/config_attribute/systems.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute/systems.rb | Apache-2.0 |
def included(plugin_class)
::Kitchen::Terraform::FilePathConfigAttributeDefiner.new(
attribute: self,
schema: ::Kitchen::Terraform::ConfigAttributeContract::ArrayOfStrings.new,
).define plugin_class: plugin_class
end | A callback to define the configuration attribute which is invoked when this module is included in a plugin
class.
@param plugin_class [Kitchen::Configurable] A plugin class.
@return [void] | included | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/config_attribute/variable_files.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/config_attribute/variable_files.rb | Apache-2.0 |
def call
read_client_version
verify_version.call version: client_version
initialize_directory
create_or_select_workspace
self
end | #call executes the action.
@raise [Kitchen::StandardError] if a command fails.
@return [self] | call | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/driver/create.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/driver/create.rb | Apache-2.0 |
def initialize(config:, connection:, logger:, version_requirement:, workspace_name:)
self.complete_config = config.to_hash.merge upgrade_during_init: true, workspace_name: workspace_name
self.connection = connection
self.client_version = ::Gem::Version.new "0.0.0"
self.logger = logger
self.workspace_name = workspace_name
self.workspace_new = ::Kitchen::Terraform::Command::WorkspaceNew.new config: complete_config
self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
config: complete_config,
logger: logger,
version_requirement: version_requirement,
)
self.version = ::Kitchen::Terraform::Command::Version.new
end | #initialize prepares a new instance of the class.
@param config [Hash] the configuration of the driver.
@param connection [Kitchen::Terraform::Transport::Connection] a Terraform connection.
@param logger [Kitchen::Logger] a logger for logging messages.
@param version_requirement [Gem::VersionRequirement] the required version of the Terraform client.
@param workspace_name [String] the name of the Terraform workspace to select or to create.
@option config [String] :client the pathname of the Terraform client.
@return [Kitchen::Terraform::Driver::Create] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/driver/create.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/driver/create.rb | Apache-2.0 |
def call
read_client_version
verify_version.call version: client_version
execute_workflow
self
end | #call executes the action.
@raise [Kitchen::StandardError] if a command fails.
@return [self] | call | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/driver/destroy.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/driver/destroy.rb | Apache-2.0 |
def initialize(config:, connection:, logger:, version_requirement:, workspace_name:)
self.complete_config = config.to_hash.merge upgrade_during_init: false, workspace_name: workspace_name
self.connection = connection
self.client_version = ::Gem::Version.new "0.0.0"
self.logger = logger
self.workspace_name = workspace_name
self.destroy = ::Kitchen::Terraform::Command::Destroy.new config: complete_config
self.workspace_delete_test = ::Kitchen::Terraform::Command::WorkspaceDelete.new config: complete_config
self.workspace_new_test = ::Kitchen::Terraform::Command::WorkspaceNew.new config: complete_config
self.workspace_select_test = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
self.workspace_select_default = ::Kitchen::Terraform::Command::WorkspaceSelect.new(
config: complete_config.merge(workspace_name: "default"),
)
self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
config: complete_config,
logger: logger,
version_requirement: version_requirement,
)
self.version = ::Kitchen::Terraform::Command::Version.new
end | #initialize prepares a new instance of the class.
@param config [Hash] the configuration of the driver.
@param connection [Kitchen::Terraform::Transport::Connection] a Terraform connection.
@param logger [Kitchen::Logger] a logger for logging messages.
@param version_requirement [Gem::VersionRequirement] the required version of the Terraform client.
@param workspace_name [String] the name of the Terraform workspace to select or to create.
@return [Kitchen::Terraform::Driver::Destroy] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/driver/destroy.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/driver/destroy.rb | Apache-2.0 |
def exec
hosts.each do |host|
::Kitchen::Terraform::InSpecRunner.new(
options: options.merge(host: host),
profile_locations: profile_locations,
).exec
end
self
end | exec executes the InSpec controls of an InSpec profile.
@raise [Kitchen::TransientFailure] if the execution of InSpec fails.
@return [self] | exec | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/inspec/fail_fast_with_hosts.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec/fail_fast_with_hosts.rb | Apache-2.0 |
def initialize(hosts:, options:, profile_locations:)
self.hosts = hosts
self.options = options
self.profile_locations = profile_locations
end | #initialize prepares a new instance of the class.
@param hosts [Array<::String>] the names or addresses of hosts on which Inspec controls will be executed.
@param options [Hash] options for execution.
@param profile_locations [Array<::String>] the locations of the InSpec profiles which contain the controls
to be executed.
@return [Kitchen::Terraform::InSpec::FailFastWithHosts] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/inspec/fail_fast_with_hosts.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec/fail_fast_with_hosts.rb | Apache-2.0 |
def exec
hosts.each do |host|
exec_and_continue host: host
end
raise ::Kitchen::TransientFailure, messages.join("\n\n") if !messages.empty?
self
end | exec executes the InSpec controls of an InSpec profile.
@raise [Kitchen::TransientFailure] if the execution of InSpec fails.
@return [self] | exec | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb | Apache-2.0 |
def initialize(hosts:, options:, profile_locations:)
self.hosts = hosts
self.messages = []
self.options = options
self.profile_locations = profile_locations
end | #initialize prepares a new instance of the class.
@param hosts [Array<::String>] the names or addresses of hosts on which Inspec controls will be executed.
@param options [Hash] options for execution.
@param profile_locations [Array<::String>] the locations of the InSpec profiles which contain the controls
to be executed.
@return [Kitchen::Terraform::InSpec::FailSlowWithHosts] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb | Apache-2.0 |
def exec
::Kitchen::Terraform::InSpecRunner.new(options: options, profile_locations: profile_locations).exec
self
end | #exec executes the InSpec controls of an InSpec profile.
@raise [Kitchen::TransientFailure] if the execution of InSpec fails.
@return [self] | exec | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/inspec/without_hosts.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec/without_hosts.rb | Apache-2.0 |
def initialize(options:, profile_locations:)
self.options = options
self.profile_locations = profile_locations
end | #initialize prepares a new instance of the class.
@param options [Hash] a mapping of InSpec options.
@param profile_locations [Array<::String>] the locations of the InSpec profiles which contain the controls
to be executed.
@return [Kitchen::Terraform::InSpec::WithoutHosts] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/inspec/without_hosts.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/inspec/without_hosts.rb | Apache-2.0 |
def call(state:)
read_client_version
verify_version.call version: client_version
execute_workflow
save_variables_and_outputs state: state
self
end | #call executes the action.
@param state [Hash] the Kitchen instance state.
@raise [Kitchen::TransientFailure] if a command fails.
@return [self] | call | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/provisioner/converge.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/provisioner/converge.rb | Apache-2.0 |
def initialize(config:, connection:, debug_connection:, logger:, version_requirement:, workspace_name:)
self.complete_config = config.to_hash.merge workspace_name: workspace_name
self.client_version = ::Gem::Version.new "0.0.0"
self.connection = connection
self.debug_connection = debug_connection
self.logger = logger
self.workspace_name = workspace_name
initialize_commands
initialize_outputs_handlers
self.variables = complete_config.fetch :variables
self.variables_manager = ::Kitchen::Terraform::VariablesManager.new
self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
config: complete_config,
logger: logger,
version_requirement: version_requirement,
)
end | #initialize prepares a new instance of the class.
@param config [Hash] the configuration of the driver.
@param connection [Kitchen::Terraform::Transport::Connection] a Terraform connection.
@param debug_connection [Kitchen::Terraform::Transport::Connection] a Terraform connection that logs at the
debug level.
@param logger [Kitchen::Logger] a logger for logging messages.
@param version_requirement [Gem::VersionRequirement] the required version of the Terraform client.
@param workspace_name [String] the name of the Terraform workspace to select or to create.
@return [Kitchen::Terraform::Driver::Converge] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/provisioner/converge.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/provisioner/converge.rb | Apache-2.0 |
def call(message:)
logger.error message
raise ::Kitchen::ActionFailed, message
end | #call logs an error message and raises an error with the message.
@param message [String] the error message.
@raise [Kitchen::ActionFailed]
@return [void] | call | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/raise/action_failed.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/raise/action_failed.rb | Apache-2.0 |
def initialize(logger:)
self.logger = logger
end | #initialize prepares a new instance of the class.
@param logger [Kitchen::Logger] a logger to log messages.
@return [Kitchen::Terraform::ActionFailed] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/raise/action_failed.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/raise/action_failed.rb | Apache-2.0 |
def call(message:)
logger.error message
raise ::Kitchen::ClientError, message
end | #call logs an error message and raises an error with the message.
@param message [String] the error message.
@raise [Kitchen::ClientError]
@return [void] | call | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/raise/client_error.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/raise/client_error.rb | Apache-2.0 |
def initialize(logger:)
self.logger = logger
end | #initialize prepares a new instance of the class.
@param logger [Kitchen::Logger] a logger to log messages.
@return [Kitchen::Terraform::ClientError] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/raise/client_error.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/raise/client_error.rb | Apache-2.0 |
def initialize(systems:)
self.systems = systems
end | #initialize prepares a new instance of the class.
@param systems [Array<::Kitchen::Terraform::System>] a list of systems to be verified.
@return [Kitchen::Terraform::SystemsVerifier::FailFast] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/systems_verifier/fail_fast.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/systems_verifier/fail_fast.rb | Apache-2.0 |
def verify(outputs:, variables:)
systems.each do |system|
system.verify fail_fast: true, outputs: outputs, variables: variables
end
self
end | #verify verifies each system.
@param outputs [Hash] a mapping of Terraform outputs.
@param variables [Hash] a mapping of Terraform variables.
@raise [Kitchen::TransientFailure] if verification of a system fails.
@return [self] | verify | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/systems_verifier/fail_fast.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/systems_verifier/fail_fast.rb | Apache-2.0 |
def initialize(systems:)
self.messages = []
self.systems = systems
end | #initialize prepares a new instance of the class.
@param systems [Array<::Kitchen::Terraform::System>] a list of systems to be verified.
@return [Kitchen::Terraform::SystemsVerifier::FailSlow] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/systems_verifier/fail_slow.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/systems_verifier/fail_slow.rb | Apache-2.0 |
def verify(outputs:, variables:)
systems.each do |system|
verify_and_continue outputs: outputs, system: system, variables: variables
end
raise ::Kitchen::TransientFailure, messages.join("\n\n") if !messages.empty?
self
end | #verify verifies each system.
@param outputs [Hash] a mapping of Terraform outputs.
@param variables [Hash] a mapping of Terraform variables.
@raise [Kitchen::TransientFailure] if verification of a system fails.
@return [self] | verify | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/systems_verifier/fail_slow.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/systems_verifier/fail_slow.rb | Apache-2.0 |
def execute(command)
super "#{client} #{command}"
stdout
end | #execute executes a Terraform CLI command on the local host.
@param command [String] the Terraform command to be executed locally.
@return [String] the standard output of the command.
@raise [Kitchen::Transport::TransportFailed] if the command does not exit successfully. | execute | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/transport/connection.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/transport/connection.rb | Apache-2.0 |
def run_command(command, options = {})
self.stdout = super command, options.merge(
cwd: root_module_directory,
environment: environment.merge("LC_ALL" => nil, "TF_IN_AUTOMATION" => "true"),
timeout: command_timeout,
)
end | #run_command executes a command in a subshell on the local running system.
@param command [String] the command to be executed locally.
@param options [Hash] additional configuration of the command.
@return [String] the standard output of the command.
@raise [Kitchen::ShellOut::ShellCommandFailed] if the command fails.
@raise [Kitchen::StandardError] for all other unexpected exceptions. | run_command | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/transport/connection.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/transport/connection.rb | Apache-2.0 |
def init_options(options)
super
self.client = options.delete :client
self.command_timeout = options.delete :command_timeout
self.environment = options.delete(:environment) || {}
self.root_module_directory = options.delete :root_module_directory
end | #init_options initializes incoming options for use by the object.
@param options [Hash] configuration options.
@return [void]
@api private | init_options | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/transport/connection.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/transport/connection.rb | Apache-2.0 |
def call
logger.warn message
self
end | #call warns the user that the version is unsupported.
@return [self] | call | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/verify_version_rescue_strategy/permissive.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/verify_version_rescue_strategy/permissive.rb | Apache-2.0 |
def initialize(logger:)
self.logger = logger
self.message = "Verifying the Terraform client version failed. Set `driver.verify_version: true` to " \
"upgrade this warning to an error."
end | #initialize prepares a new instance of the class.
@param logger [Kitchen::Logger] a logger to log messages.
@return [Kitchen::Terraform::VerifyVersionRescueStrategy::Permissive] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/verify_version_rescue_strategy/permissive.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/verify_version_rescue_strategy/permissive.rb | Apache-2.0 |
def call
raise ::Kitchen::Terraform::UnsupportedClientVersionError, message
end | #call raises an error.
@raise [Kitchen::Terraform::UnsupportedClientVersionError]
@return [void] | call | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/verify_version_rescue_strategy/strict.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/verify_version_rescue_strategy/strict.rb | Apache-2.0 |
def initialize
self.message = "Verifying the Terraform client version failed. Set `driver.verify_version: false` to " \
"downgrade this error to a warning."
end | #initialize prepares a new instance of the class.
@return [Kitchen::Terraform::VerifyVersionRescueStrategy::Permissive] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/verify_version_rescue_strategy/strict.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/verify_version_rescue_strategy/strict.rb | Apache-2.0 |
def call
raise ::Kitchen::Terraform::UnsupportedClientVersionError, "The Terraform client version is unsupported."
end | #call fails the verification.
@raise [Kitchen::Terraform::UnsupportedClientVersionError]
@return [void] | call | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/terraform/version_verifier_strategy/unsupported.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/terraform/version_verifier_strategy/unsupported.rb | Apache-2.0 |
def connection(state, &block)
options = connection_options config.to_hash.merge state
::Kitchen::Terraform::Transport::Connection.new options, &block
end | #connection creates a new Connection, configured by a merging of configuration
and state data.
@param state [Hash] mutable instance state.
@return [Kitchen::Terraform::Transport::Connection] a connection for this transport.
@raise [Kitchen::Transport::TransportFailed] if a connection could not be returned. | connection | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/transport/terraform.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/transport/terraform.rb | Apache-2.0 |
def doctor(_state)
errors = false
methods.each do |method|
next if !method.match? /doctor_config_.*/
error = send method
errors = errors || error
end
errors
end | doctor checks the system and configuration for common errors.
@param _state [Hash] the mutable Kitchen instance state.
@return [Boolean] +true+ if any errors are found; +false+ if no errors are found. | doctor | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/transport/terraform.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/transport/terraform.rb | Apache-2.0 |
def finalize_config!(instance)
super instance
self
end | #finalize_config! invokes the super implementation and then initializes the strategies.
@param instance [Kitchen::Instance] an associated instance.
@raise [Kitchen::ClientError] if the instance is nil.
@return [self] | finalize_config! | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/transport/terraform.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/transport/terraform.rb | Apache-2.0 |
def initialize(config = {})
super config
end | #initialize prepares a new instance of the class.
@param config [Hash] the transport configuration.
@return [Kitchen::Transport::Terraform] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/transport/terraform.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/transport/terraform.rb | Apache-2.0 |
def connection_options(data)
opts = super.merge! data
opts.merge! logger: logger if !opts.key? :logger
opts
end | #connection_options builds the hash of options needed by the Connection object on construction.
@param data [Hash] merged configuration and mutable state data.
@return [Hash] hash of connection options.
@api private | connection_options | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/transport/terraform.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/transport/terraform.rb | Apache-2.0 |
def call(state)
load_variables state: state
load_outputs state: state
verify_systems
rescue => error
action_failed.call message: error.message
end | The verifier enumerates through each host of each system and verifies the associated InSpec controls.
@example
`kitchen verify suite-name`
@param state [Hash] the mutable instance and verifier state.
@raise [Kitchen::ActionFailed] if the result of the action is a failure.
@return [void] | call | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/verifier/terraform.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/verifier/terraform.rb | Apache-2.0 |
def doctor(_state)
errors = false
methods.each do |method|
next if !method.match? /doctor_config_.*/
error = send method
errors = errors || error
end
errors
end | doctor checks the system and configuration for common errors.
@param _state [Hash] the mutable Kitchen instance state.
@return [Boolean] +true+ if any errors are found; +false+ if no errors are found. | doctor | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/verifier/terraform.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/verifier/terraform.rb | Apache-2.0 |
def initialize(config = {})
init_config config
self.action_failed = ::Kitchen::Terraform::Raise::ActionFailed.new logger: logger
self.client_error = ::Kitchen::Terraform::Raise::ClientError.new logger: logger
self.outputs = {}
self.variables = {}
end | #initialize prepares a new instance of the class.
@param config [Hash] the verifier configuration.
@return [Kitchen::Verifier::Terraform] | initialize | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/verifier/terraform.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/verifier/terraform.rb | Apache-2.0 |
def load_needed_dependencies!
require "kitchen/terraform/inspec_runner"
require "kitchen/terraform/system"
::Kitchen::Terraform::InSpecRunner.logger = logger
rescue ::LoadError => load_error
client_error.call message: load_error.message
end | load_needed_dependencies! loads the InSpec libraries required to verify a Terraform state.
@raise [Kitchen::ClientError] if loading the InSpec libraries fails.
@see https://github.com/test-kitchen/test-kitchen/blob/v1.21.2/lib/kitchen/configurable.rb#L252-L274 | load_needed_dependencies! | ruby | newcontext-oss/kitchen-terraform | lib/kitchen/verifier/terraform.rb | https://github.com/newcontext-oss/kitchen-terraform/blob/master/lib/kitchen/verifier/terraform.rb | Apache-2.0 |
def initialize candidate, options = {}
raise "Candidate must be something!" if !candidate
@candidate, @options = candidate, options
clear_rules!
permit_rules
execute_engines! if engines_on?
end | Equivalent to a CanCan Ability#initialize call
which executes all the permission logic | initialize | ruby | kristianmandrup/cantango | lib/cantango/ability.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/ability.rb | MIT |
def initialize candidate, options = {}
raise "Candidate must be something!" if !candidate
@candidate, @options = candidate, options
# return if cached_rules?
clear_rules!
permit_rules
execute_engines! if engines_on?
# cache_rules!
end | Equivalent to a CanCan Ability#initialize call
which executes all the permission logic | initialize | ruby | kristianmandrup/cantango | lib/cantango/cached_ability.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/cached_ability.rb | MIT |
def enable_defaults!
engines.all :on
adapters.use :compiler
end | Turn on all engines and enable compile adapter
i.e compilation of rules via sourcify | enable_defaults! | ruby | kristianmandrup/cantango | lib/cantango/configuration.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/configuration.rb | MIT |
def engine name, &block
engine = find_engine(name)
yield engine if block
engine
end | allow either block or direct access
engine(:permission) do |permission|
engine(:permission).config_path | engine | ruby | kristianmandrup/cantango | lib/cantango/configuration.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/configuration.rb | MIT |
def roles
return [] if !subject.respond_to?(roles_list_meth) || roles_of(subject).blank?
roles_of(subject).flatten
end | return list roles the user has | roles | ruby | kristianmandrup/cantango | lib/cantango/ability/role_helpers.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/ability/role_helpers.rb | MIT |
def role_groups
return [] if !subject.respond_to?(role_groups_list_meth) || role_groups_of(subject).blank?
role_groups_of(subject).flatten
end | return list of symbols for role groups the user belongs to | role_groups | ruby | kristianmandrup/cantango | lib/cantango/ability/role_helpers.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/ability/role_helpers.rb | MIT |
def initialize name, options = {}
super
@store = CanTango::Cache::MonetaCache.instance
@store.configure_with options
end | for a YamlStore, the name is the name of the yml file | initialize | ruby | kristianmandrup/cantango | lib/cantango/ability/cache/moneta_cache.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/ability/cache/moneta_cache.rb | MIT |
def initialize name, options = {}
super # will set all instance vars using options hash
@cache = cache
@cache.configure_with :type => :memory
raise "SessionCache must be initialized with a :session option" if !session
session[cache_key] = @cache
end | will be called with :session => session (pointing to user session) | initialize | ruby | kristianmandrup/cantango | lib/cantango/ability/cache/session_cache.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/ability/cache/session_cache.rb | MIT |
def any_user *types
types = types.flatten.select_labels.map(&:to_sym)
c_user = ::CanTango.config.users.registered.each do |user|
meth = :"current_#{user}"
send(meth) if respond_to?(meth) && (types.empty? || types.include?(user))
end.compact.first
c_user || guest_user
end | give me any logged in user or the guest user | any_user | ruby | kristianmandrup/cantango | lib/cantango/api/user/session.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/api/user/session.rb | MIT |
def any_account *types
types = types.flatten.select_labels.map(&:to_sym)
c_account = ::CanTango.config.user_accounts.registered.each do |type|
meth = :"current_#{type}_account"
send(meth) if respond_to?(meth) && (types.empty? || types.include?(user))
end.compact.first
c_account || guest_account
end | give me any logged in user or the guest user | any_account | ruby | kristianmandrup/cantango | lib/cantango/api/user_account/session.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/api/user_account/session.rb | MIT |
def has_any? subject, &block
found = registered.any? {|cat, subjects| subjects.include? subject }
yield if found && block
found
end | test if a any of the categories contain the subject | has_any? | ruby | kristianmandrup/cantango | lib/cantango/configuration/categories.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/configuration/categories.rb | MIT |
def categories_of_subject subject, &block
found_categories = registered.select do |cat, subjects|
subjects.include? subject.to_s
end
found_categories.empty? ? {} : found_categories
end | find the category of a subject if such a category exists | categories_of_subject | ruby | kristianmandrup/cantango | lib/cantango/configuration/categories.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/configuration/categories.rb | MIT |
def has_any? subject, &block
found = subjects.include? subject
yield if found && block
found
end | test if a particular category has a certain subject | has_any? | ruby | kristianmandrup/cantango | lib/cantango/configuration/categories.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/configuration/categories.rb | MIT |
def registered
@registered ||= default_register
end | engine factories ?
:cache => Cantango::Ability::Cache | registered | ruby | kristianmandrup/cantango | lib/cantango/configuration/engines.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/configuration/engines.rb | MIT |
def engine? engine_class
[:execute!, :ability].all? {|meth| engine_class.instance_methods.include? meth }
end | does it implement the basic Engine API? | engine? | ruby | kristianmandrup/cantango | lib/cantango/configuration/engines.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/configuration/engines.rb | MIT |
def build_statements method, &block
return nil if !permission.static_rules.send(method)
yield statements(method) if !statements(method).empty? && block
statements(method)
end | build the 'can' or 'cannot' statements to evaluate | build_statements | ruby | kristianmandrup/cantango | lib/cantango/permission_engine/compiler.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/permission_engine/compiler.rb | MIT |
def get_targets method, action
permission.static_rules.send(method).send(:[], action.to_s)
end | returns the targets the permission rule can manage
Example: permission.can[:manage]
returns ['Article', 'Comment'] | get_targets | ruby | kristianmandrup/cantango | lib/cantango/permission_engine/compiler.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/permission_engine/compiler.rb | MIT |
def statements_string method, options = {}
action = options[:action]
targets = get_targets method, action
targets ? CanTango::PermissionEngine::Statements.new(method, action, targets).to_code : nil
end | TODO can and cannot should allow for multiple actions!
TODO: should be refactored to more like can([:read, :write], [Article, Comment])
Example: can(:manage, [Article, Comment]) | statements_string | ruby | kristianmandrup/cantango | lib/cantango/permission_engine/compiler.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/permission_engine/compiler.rb | MIT |
def initialize name, options = {}
super
@store = CanTango::Cache::MonetaCache.instance
@store.configure_with options
end | for a YamlStore, the name is the name of the yml file | initialize | ruby | kristianmandrup/cantango | lib/cantango/permission_engine/moneta_store.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/permission_engine/moneta_store.rb | MIT |
def parser target
CanTango::PermissionEngine::Parser.create_for method, action, target
end | def statement target_and_conditions
CanTango::PermissionEngine::Statement.new method, action, target_and_conditions
end | parser | ruby | kristianmandrup/cantango | lib/cantango/permission_engine/statements.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/permission_engine/statements.rb | MIT |
def permissions
return @permissions if changed?
@permissions = loader.permissions
end | return cached permissions if file has not changed since last load
otherwise load permissions again to reflect changes! | permissions | ruby | kristianmandrup/cantango | lib/cantango/permission_engine/yaml_store.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/permission_engine/yaml_store.rb | MIT |
def parse_permission(obj, permission, &blk)
# Forget keys because I don't know what to do with them
obj.each do |key, value|
raise ArgumentError, "A CanTango permissions .yml file can only have the keys can: and cannot:" if ![:can, :cannot].include?(key.to_sym)
permission.static_rules.send :"#{key}=", value
end
end | set :can and :cannot on permission with the permission rule | parse_permission | ruby | kristianmandrup/cantango | lib/cantango/permission_engine/parser/permissions.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/permission_engine/parser/permissions.rb | MIT |
def account_permit
return nil if !registered_account? user_account.class
found = account_permits_by(type)[name]
debug account_permit_msg(found)
found
rescue
nil
end | TODO: User/Account cases should be handled somehow following is just interim measure | account_permit | ruby | kristianmandrup/cantango | lib/cantango/permit_engine/finder.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/permit_engine/finder.rb | MIT |
def use_adaptor! base, object
orm_map.each_pair do |orm, const|
begin
base.class.send :include, get_adapter(object, const.constantize, orm)
rescue
next
end
end
end | include adaptor depending on which ORM the object inherits from or includes | use_adaptor! | ruby | kristianmandrup/cantango | lib/cantango/rules/adaptor.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/rules/adaptor.rb | MIT |
def scope name, &block
yield CanTango::Rules::Scope.new name, self, &block
end | creates a scope that enforces either using the user or user_account for determining relationship matches on the models | scope | ruby | kristianmandrup/cantango | lib/cantango/rules/dsl.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/rules/dsl.rb | MIT |
def include_condition attribute, user_scope
{ attribute.to_sym.in => user_scope.send(attribute) }
end | include CanTango::Rules::Adaptor::Generic
using #in on Hash (Mongoid query) | include_condition | ruby | kristianmandrup/cantango | lib/cantango/rules/adaptor/mongo.rb | https://github.com/kristianmandrup/cantango/blob/master/lib/cantango/rules/adaptor/mongo.rb | MIT |
def static_rules
cannot :manage, User
can :read, Comment
can :read, any(/Post/)
can :read, Article
can :write, any(/Article/)
author_of(Article) do |author|
author.can :manage
end
author_of(Post) do |author|
author.can :manage
end
author_of(Comment) do |author|
author.can :manage
end
# # can :manage, :all
# scope :account do |account|
# account.author_of(Article) do |author|
# author.can :manage
# author.cannot :delete
# end
#
# account.writer_of(Post).can :manage
# end
#
# scope :user do |user|
# user.writer_of(Comment).can :manage
# end
end | should take user and options args here ??? | static_rules | ruby | kristianmandrup/cantango | spec/active_record/scenarios/shared/permits/account_permits/user_account_permit.rb | https://github.com/kristianmandrup/cantango/blob/master/spec/active_record/scenarios/shared/permits/account_permits/user_account_permit.rb | MIT |
def permissions_hash
@permissions_hash = permissions.hash
end | This hash should be recalculated anytime the permissions collection changes
after_update :recalculate_permissions_hash | permissions_hash | ruby | kristianmandrup/cantango | spec/fixtures/models/user.rb | https://github.com/kristianmandrup/cantango/blob/master/spec/fixtures/models/user.rb | MIT |
def cached_rules
time_initial = time_now
puts "#cached_rules:"
rules_compiled = rules_cache.load(cache_key)
time = time_now - time_initial
puts " loading rules from store: (#{time}ms)"
rules_raw = decompile_rules! rules_compiled
time = time_now - time_initial
puts " decompiling rules: (#{time}ms)"
@rules ||= rules_raw
end | No #stamper here.
Wrapping decompilator in block causes decompiler (i.e. sourcify) is not working | cached_rules | ruby | kristianmandrup/cantango | spec/integration/performance/helpers/cache.rb | https://github.com/kristianmandrup/cantango/blob/master/spec/integration/performance/helpers/cache.rb | MIT |
def text(str)
@headers[Rack::CONTENT_TYPE] = ContentType::TEXT
write(str)
end | Write response body as text/plain | text | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def html(str)
@headers[Rack::CONTENT_TYPE] = ContentType::HTML
write(str)
end | Write response body as text/html | html | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def json(str)
@headers[Rack::CONTENT_TYPE] = ContentType::JSON
write(str)
end | Write response body as application/json | json | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def on(*args, &block)
try do
# For every block, we make sure to reset captures so that
# nesting matchers won't mess with each other's captures.
@captures = []
# We stop evaluation of this entire matcher unless
# each and every `arg` defined for this matcher evaluates
# to a non-false value.
#
# Short circuit examples:
# on true, false do
#
# # PATH_INFO=/user
# on true, "signup"
return unless args.all? { |arg| match(arg) }
# The captures we yield here were generated and assembled
# by evaluating each of the `arg`s above. Most of these
# are carried out by #consume.
yield(*captures)
if res.status.nil?
if res.body.empty?
not_found
else
res.headers[Rack::CONTENT_TYPE] ||= DEFAULT
res.status = 200
end
end
halt(res.finish)
end
end | The heart of the path / verb / any condition matching.
@example
on get do
res.write "GET"
end
on get, "signup" do
res.write "Signup"
end
on "user/:id" do |uid|
res.write "User: #{uid}"
end
on "styles", extension("css") do |file|
res.write render("styles/#{file}.sass")
end | on | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def try
script, path = env[Rack::SCRIPT_NAME], env[Rack::PATH_INFO]
yield
ensure
env[Rack::SCRIPT_NAME], env[Rack::PATH_INFO] = script, path
end | @private Used internally by #on to ensure that SCRIPT_NAME and
PATH_INFO are reset to their proper values. | try | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def extension(ext = "\\w+")
lambda { consume("([^\\/]+?)\.#{ext}\\z") }
end | A matcher for files with a certain extension.
@example
# PATH_INFO=/style/app.css
on "style", extension("css") do |file|
res.write file # writes app
end | extension | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def param(key, default = nil)
value = req.params[key.to_s] || default
lambda { captures << value unless value.to_s.empty? }
end | Ensures that certain request parameters are present. Acts like a
precondition / assertion for your route. A default value can be
provided as a second argument. In that case, it always matches
and the result is either the parameter or the default value.
@example
# POST with data like user[fname]=John&user[lname]=Doe
on "signup", param("user") do |atts|
User.create(atts)
end
on "login", param("username", "guest") do |username|
# If not provided, username == "guest"
end | param | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def host(hostname)
hostname === req.host
end | Useful for matching against the request host (i.e. HTTP_HOST).
@example
on host("account1.example.com"), "api" do
res.write "You have reached the API of account1."
end | host | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def accept(mimetype)
lambda do
accept = String(env["HTTP_ACCEPT"]).split(",")
if accept.any? { |s| s.strip == mimetype }
res[Rack::CONTENT_TYPE] = mimetype
end
end
end | If you want to match against the HTTP_ACCEPT value.
@example
# HTTP_ACCEPT=application/xml
on accept("application/xml") do
# automatically set to application/xml.
res.write res["Content-Type"]
end | accept | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def root
env[Rack::PATH_INFO] == SLASH || env[Rack::PATH_INFO] == EMPTY
end | Access the root of the application.
@example
# GET /
on root do
res.write "Home"
end | root | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def run(app)
halt app.call(req.env)
end | If you want to halt the processing of an existing handler
and continue it via a different handler.
@example
def redirect(*args)
run Cuba.new { on(default) { res.redirect(*args) }}
end
on "account" do
redirect "/login" unless session["uid"]
res.write "Super secure account info."
end | run | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def with(dict = {})
old, env["cuba.vars"] = vars, vars.merge(dict)
yield
ensure
env["cuba.vars"] = old
end | Adds ability to pass information to a nested Cuba application.
It receives two parameters: a hash that represents the passed
information and a block. The #vars method is used to retrieve
a hash with the passed information.
class Platforms < Cuba
define do
platform = vars[:platform]
on default do
res.write(platform) # => "heroku" or "salesforce"
end
end
end
Cuba.define do
on "(heroku|salesforce)" do |platform|
with(platform: platform) do
run(Platforms)
end
end
end | with | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def vars
env["cuba.vars"] ||= {}
end | Returns a hash with the information set by the #with method.
with(role: "admin", site: "main") do
on default do
res.write(vars.inspect)
end
end
# => '{:role=>"admin", :site=>"main"}' | vars | ruby | soveran/cuba | lib/cuba.rb | https://github.com/soveran/cuba/blob/master/lib/cuba.rb | MIT |
def _render(template, locals = {}, options = {}, &block)
_cache.fetch(template) {
Tilt.new(template, 1, options.merge(outvar: '@_output'))
}.render(self, locals, &block)
end | @private Renders any type of template file supported by Tilt.
@example
# Renders home, and is assumed to be HAML.
_render("home.haml")
# Renders with some local variables
_render("home.haml", site_name: "My Site")
# Renders with HAML options
_render("home.haml", {}, ugly: true, format: :html5)
# Renders in layout
_render("layout.haml") { _render("home.haml") } | _render | ruby | soveran/cuba | lib/cuba/render.rb | https://github.com/soveran/cuba/blob/master/lib/cuba/render.rb | MIT |
def _cache
Thread.current[:_cache] ||= Tilt::Cache.new
end | @private Used internally by #_render to cache the
Tilt templates. | _cache | ruby | soveran/cuba | lib/cuba/render.rb | https://github.com/soveran/cuba/blob/master/lib/cuba/render.rb | MIT |
def region
defined?(super) ? super : "us-east-1"
end | ensure that region returns something. Since sig v4 it is required in the signing key & credentials | region | ruby | dwilkie/carrierwave_direct | lib/carrierwave_direct/uploader.rb | https://github.com/dwilkie/carrierwave_direct/blob/master/lib/carrierwave_direct/uploader.rb | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.