lib/conifer.rb in conifer-0.1.0 vs lib/conifer.rb in conifer-0.2.0
- old
+ new
@@ -1,25 +1,27 @@
# frozen_string_literal: true
require 'conifer/version'
require 'conifer/file'
-require 'active_support/all'
+require 'active_support/concern'
module Conifer
extend ActiveSupport::Concern
- included do
- def conifer
- self.class.__conifer
- end
- end
-
class_methods do
- attr_reader :__conifer
+ def conifer(file, prefix: nil, dir: nil, method: 'conifer', singleton: false)
+ body = proc do
+ return instance_variable_get("@conifer_#{method}") if instance_variable_defined?("@conifer_#{method}")
- def conifer(file, prefix: nil, dir: nil)
- directory = dir.presence || ::File.expand_path(::File.dirname(caller_locations.first.path))
- @__conifer = Conifer::File.new(file, prefix: prefix, dir: directory)
+ directory = dir || ::File.expand_path(::File.dirname(caller_locations.first.path))
+ instance_variable_set "@conifer_#{method}", Conifer::File.new(file, prefix: prefix, dir: directory)
+ end
+
+ if singleton
+ define_singleton_method method, &body
+ else
+ define_method method, &body
+ end
end
end
end