Module: Croesus::ModFactory

Includes:
Utils
Included in:
ResourceDSL
Defined in:
lib/croesus/dsl/mod_factory.rb

Overview

Mysteries abound, dynamic box of factory creation for API resources.

Instance Method Summary collapse

Methods included from Utils

#callable, #caller_name, #camelize, #class_name, #classify, #command_in_path?, #demodulize, #pluralize, #request_id, #retrier, #singularize, #terminal_dimensions, #twenty_four_hours_ago, #underscore, #utc_httpdate, #verify_options

Instance Method Details

#add_description(description) ⇒ Nil

Sets the description the Delphix Resource.

Parameters:

  • description (String)

    the description of the API resource

Returns:

  • (Nil)


56
57
58
59
# File 'lib/croesus/dsl/mod_factory.rb', line 56

def add_description(description)
  @mod.instance_variable_set(:@description, description)
  @mod.define_singleton_method(:description) { @description }
end

#add_method(dsl_object) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/croesus/dsl/mod_factory.rb', line 74

def add_method(dsl_object)
  raw = dsl_object.to_hash
  name = raw[:name]
  verb = raw[:verb]
  @mod.methods[name] = raw[:description]
  @mod.singleton_class.send(:alias_method, name, "api_#{verb.downcase}")
  define_help
end

#add_root_endpoint(root) ⇒ Nil

Sets the root endpoint for the resource.

Parameters:

  • root (String)

    the root endpoint for the resource

Returns:

  • (Nil)


69
70
71
72
# File 'lib/croesus/dsl/mod_factory.rb', line 69

def add_root_endpoint(root)
  @mod.instance_variable_set(:@root, root)
  @mod.define_singleton_method(:root) { @root }
end

#initialize(name, mod = Module.new) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/croesus/dsl/mod_factory.rb', line 40

def initialize(name, mod = Module.new)
  @mod = mod
  @name = name
  Croesus::AnonoMod.register(name, @mod)
  assemble_module
  @mod
end