class Object
Public Class Methods
append_validator(validator)
click to toggle source
# File lib/croesus/validations.rb, line 52 def self.append_validator(validator) unless validator.is_a?(Croesus::Validator::Base) raise ValidationError.new( 'Validators inherit from Croesus::Validator::Base' ) end if @@validators.detect { |v| v.name == validator.name } raise ValidationError.new('Validators must have unique names.') end @@validators << validator end
validator_for(item)
click to toggle source
# File lib/croesus/validations.rb, line 66 def self.validator_for(item) @@validators.detect { |v| v.should_validate?(item) } || raise(ValidationError.new("Could not find valid validator for: #{item}")) end
Public Instance Methods
add_included_hook()
click to toggle source
# File lib/croesus/dsl/mod_factory.rb, line 168 def add_included_hook @mod.send :include, Croesus::BasicMethods @mod.send :include, CommandLineReporter @mod.send :include, Croesus::Utils end
add_instance_variables()
click to toggle source
# File lib/croesus/dsl/mod_factory.rb, line 174 def add_instance_variables @mod.instance_variable_set(:@delphix_object, classify(@name)) @mod.define_singleton_method(:delphix_object) { @delphix_object } @mod.instance_variable_set(:@methods, {}) @mod.define_singleton_method(:methods) { @methods } end
assemble_module()
click to toggle source
# File lib/croesus/dsl/mod_factory.rb, line 161 def assemble_module add_included_hook add_instance_variables be_polite_and_debuggable define_verbs('get', 'post', 'delete') end
be_polite_and_debuggable()
click to toggle source
# File lib/croesus/dsl/mod_factory.rb, line 182 def be_polite_and_debuggable @mod.define_singleton_method :to_s do "<#{self.class.name}:#{self.name}:#{object_id}>" end @mod.define_singleton_method :inspect do "<#{self.class.name}:#{self.name}:#{object_id} #{instance_variables}>" end end
blank?()
click to toggle source
Returns true if the object is nil or empty (if applicable)
[].blank? #=> true [1].blank? #=> false [nil].blank? #=> false
@return [TrueClass, FalseClass]
# File lib/croesus/core_ext/blank.rb, line 30 def blank? nil? || (respond_to?(:empty?) && empty?) end
define_api_verb(verb)
click to toggle source
Internal: Defines a method to handle HTTP requests with the passed in verb to a api endpoint.
verb - Symbol name of the verb (e.g. :get).
Examples
define_api_verb :get # => api_get '/resources/json/delphix/environment'
Returns nil.
# File lib/croesus/dsl/mod_factory.rb, line 129 def define_api_verb(verb) @mod.define_singleton_method("api_#{verb}") do |*args, &block| class_eval "Croesus.#{verb}(url(*args)).body" end end
define_help()
click to toggle source
# File lib/croesus/dsl/mod_factory.rb, line 135 def define_help @mod.define_singleton_method :help do puts dyno_width = terminal_dimensions[0] - 32 header title: "Available commands for #{@delphix_object}", align: 'center', width: terminal_dimensions[0] table border: true do row header: true, color: 'red' do column 'Num', width: 3, align: 'right', color: 'blue', padding: 0 column 'Method Name', width: 18, align: 'left', padding: 0 column "Description (http://#{Croesus.server}/api/#" \ "#{@delphix_object.downcase})", width: dyno_width, align: 'left', padding: 0 end (@methods.keys).sort.each.with_index(1) do |method, i| row do column '%02d' % i column method column @methods[method.to_sym] end end end puts @description end end
define_verb(verb)
click to toggle source
Internal: Defines a method to handle HTTP requests with the passed in verb.
verb - Symbol name of the verb (e.g. :get).
Examples
define_verb :get # => get 'http://server.xyz/path'
Returns nil.
# File lib/croesus/dsl/mod_factory.rb, line 112 def define_verb(verb) @mod.define_singleton_method(verb.to_sym) do |*args, &block| class_eval "Croesus.#{verb}" end end
present?()
click to toggle source
Returns true if the object is NOT nil or empty
[].present? #=> false [1].present? #=> true [nil].present? #=> true
@return [TrueClass, FalseClass]
# File lib/croesus/core_ext/blank.rb, line 42 def present? !blank? end