Class: Grifter
- Includes:
- Configuration, Instrumentation
- Defined in:
- lib/grifter.rb,
lib/grifter/log.rb,
lib/grifter/helpers.rb,
lib/grifter/http_service.rb,
lib/grifter/json_helpers.rb,
lib/grifter/configuration.rb,
lib/grifter/instrumentation.rb
Defined Under Namespace
Modules: Configuration, Helpers, Instrumentation, JsonHelpers, Log Classes: HTTPService, RequestException
Constant Summary collapse
- DefaultConfigOptions =
{ #TODO: service_config: nil, grift_globs: ['*_grifts/**/*_grifts.rb'], authenticate: false, load_from_config_file: true, services: {}, instrumentation: false, }
Instance Attribute Summary collapse
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Instance Method Summary collapse
-
#grifter_authenticate_do ⇒ Object
calls all methods that end with grifter_authenticate.
-
#grifter_configuration ⇒ Object
this allows configuration to be accessed in grift scripts.
-
#initialize(options = {}) ⇒ Grifter
constructor
A new instance of Grifter.
- #load_grifter_file(filename) ⇒ Object
- #run_script_file(filename) ⇒ Object
Methods included from Instrumentation
#metrics_all_requests, #start_instrumentation
Methods included from Configuration
#get_service_config_from_url, #load_config_file, #normalize_config, #recursive_symbolize
Constructor Details
#initialize(options = {}) ⇒ Grifter
Returns a new instance of Grifter.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/grifter.rb', line 19 def initialize ={} = DefaultConfigOptions.merge() @config = if [:load_from_config_file] .merge load_config_file() else end #setup the services @services = [] @config[:services].each_pair do |service_name, service_config| service = HTTPService.new(service_config) define_singleton_method service_name.intern do service end @services << service end #setup the grifter methods if any if @config[:grift_globs] @config[:grift_globs].each do |glob| Dir[glob].each do |grifter_file| load_grifter_file grifter_file end end end if @config[:authenticate] self.grifter_authenticate_do end start_instrumentation if @config[:instrumentation] = true end |
Instance Attribute Details
#services ⇒ Object (readonly)
Returns the value of attribute services.
53 54 55 |
# File 'lib/grifter.rb', line 53 def services @services end |
Instance Method Details
#grifter_authenticate_do ⇒ Object
calls all methods that end with grifter_authenticate
81 82 83 84 85 86 87 |
# File 'lib/grifter.rb', line 81 def grifter_authenticate_do auth_methods = self.singleton_methods.select { |m| m =~ /grifter_authenticate$/ } auth_methods.each do |m| Log.debug "Executing a grifter_authentication on method: #{m}" self.send(m) end end |
#grifter_configuration ⇒ Object
this allows configuration to be accessed in grift scripts
56 57 58 |
# File 'lib/grifter.rb', line 56 def grifter_configuration @config.clone end |
#load_grifter_file(filename) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/grifter.rb', line 60 def load_grifter_file filename Log.debug "Loading extension file '#{filename}'" #by evaling in a anonymous module, we protect this class's namespace anon_mod = Module.new with_local_load_path File.dirname(filename) do anon_mod.class_eval(IO.read(filename), filename, 1) end self.extend anon_mod end |
#run_script_file(filename) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/grifter.rb', line 70 def run_script_file filename Log.info "Running data script '#{filename}'" raise "No such file '#{filename}'" unless File.exist? filename #by running in a anonymous class, we protect this class's namespace anon_class = BlankSlate.new(self) with_local_load_path File.dirname(filename) do anon_class.instance_eval(IO.read(filename), filename, 1) end end |