Module: CFO

Defined in:
lib/cfo/cfo.rb,
lib/cfo/service.rb,
lib/cfo/version.rb,
lib/cfo/record_filter.rb,
lib/cfo/record_grouper.rb,
lib/cfo/resources/report.rb,
lib/cfo/resources/account.rb,
lib/cfo/resources/cloud_resource.rb

Defined Under Namespace

Modules: RecordFilter, RecordGrouper Classes: Account, CloudResource, Report, Service

Constant Summary collapse

PROJECT_DIR =
File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
VERSION =

The version of this CFO Gem / Library.

"0.1.2"
API_VERSION =

This library’s version of the CFO REST API.

"1"

Class Method Summary collapse

Class Method Details

.connect_to_database(db_file = ENV['DB_CONFIG_FILE']) ⇒ Hash

Connects to the database defined in db_file. Uses the YAML section indexed by CloudCostTracker#env.

Parameters:

  • db_file (defaults to: ENV['DB_CONFIG_FILE'])

    the path to a Rails-style YAML DB config file.

Returns:

  • (Hash)

    the current envinronment’s database configuration.



13
14
15
# File 'lib/cfo/cfo.rb', line 13

def self.connect_to_database(db_file = ENV['DB_CONFIG_FILE'])
  ::CloudCostTracker.connect_to_database(db_file)
end

.envString

Returns the current RACK_ENV, or ‘development’ if not set

Returns:

  • (String)

    ENV || ENV || development



7
# File 'lib/cfo/cfo.rb', line 7

def self.env ; ::CloudCostTracker.env end

.force_timezoneObject

Forces the ActiveRecord timezone settings, which normally defaults to :local. Uncomment the code in this function ONLY if you’re using this CFO as a standalone application, and need to force the time zone. See: api.rubyonrails.org/classes/ActiveRecord/Timestamp.html



40
41
42
# File 'lib/cfo/cfo.rb', line 40

def self.force_timezone
  #ActiveRecord::Base.default_timezone = :utc
end

.read_accounts(account_file = ENV['ACCOUNT_FILE']) ⇒ Array<Account>

Loads account information defined in account_file.

Parameters:

  • account_file (defaults to: ENV['ACCOUNT_FILE'])

    the path to a YAML file (see accounts.yml.example).

Returns:

  • (Array<Account>)

    an Array of Account resources.



20
21
22
23
24
25
# File 'lib/cfo/cfo.rb', line 20

def self.read_accounts( = ENV['ACCOUNT_FILE'])
   = ::CloudCostTracker.read_accounts()
  .map do |(, )|
     = Account.new(.merge(:name => ))
  end
end

.rootString

Defines the root URI path of the CFO service.

Returns:

  • (String)

    the root URI path of the CFO service



31
32
33
# File 'lib/cfo/cfo.rb', line 31

def self.root
  "/api/v#{CFO::API_VERSION}"
end