Class: FunWith::Gems::ApiExtender
- Inherits:
-
Object
- Object
- FunWith::Gems::ApiExtender
- Defined in:
- lib/fun_with/gems/api_extender.rb
Class Method Summary collapse
Instance Method Summary collapse
- #existing_gem_api_constant ⇒ Object
- #extend_with_api ⇒ Object
- #get_gem_api_module ⇒ Object
-
#initialize(const) ⇒ ApiExtender
constructor
A new instance of ApiExtender.
- #load_api_constant ⇒ Object
Constructor Details
#initialize(const) ⇒ ApiExtender
Returns a new instance of ApiExtender.
8 9 10 |
# File 'lib/fun_with/gems/api_extender.rb', line 8 def initialize(const) @const = const end |
Class Method Details
.extend_with_api(*args, &block) ⇒ Object
4 5 6 |
# File 'lib/fun_with/gems/api_extender.rb', line 4 def self.extend_with_api( *args, &block ) self.new(*args,&block).extend_with_api end |
Instance Method Details
#existing_gem_api_constant ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/fun_with/gems/api_extender.rb', line 36 def existing_gem_api_constant return @const::GemAPI if defined?(@const::GemAPI) return @const::API if defined?(@const::API) return @const::GemApi if defined?(@const::GemApi) return nil end |
#extend_with_api ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/fun_with/gems/api_extender.rb', line 12 def extend_with_api api = get_gem_api_module if api.is_a?(Module) @const.extend( api ) end end |
#get_gem_api_module ⇒ Object
20 21 22 |
# File 'lib/fun_with/gems/api_extender.rb', line 20 def get_gem_api_module existing_gem_api_constant || load_api_constant end |
#load_api_constant ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fun_with/gems/api_extender.rb', line 24 def load_api_constant if @const.respond_to?(:root) rootpath = @const.root / :lib gem_api_path = @const.to_s.gsub("::","/").gsub(/(.)([A-Z])/,'\1_\2').downcase path = rootpath / gem_api_path require path if path.ext(:rb).file? existing_gem_api_constant # maybe it exists now? end end |