lib/arstotzka/method_builder.rb in arstotzka-1.2.3 vs lib/arstotzka/method_builder.rb in arstotzka-1.2.4
- old
+ new
@@ -87,11 +87,11 @@
# @return nil
#
# @see Sinclair
def add_attr(attribute)
klass.add_fetcher(attribute, options)
- add_method attribute, (cached ? cached_fetcher(attribute) : attr_fetcher(attribute)).to_s
+ add_method attribute, attr_fetcher(attribute), cached: cached
end
# Returns the code needed to initialize fetcher
#
# @param [String,Symbol] attribute name of method / attribute
@@ -103,22 +103,9 @@
def attr_fetcher(attribute)
<<-CODE
begin
self.class.fetcher_for(:#{attribute}, self).fetch
end
- CODE
- end
-
- # Returns the code needed to initialize a fetche and cache it
- #
- # @param [String,Symbol] attribute name of method / attribute
- #
- # @return [String] method code
- #
- # @see #attr_fetcher
- def cached_fetcher(attribute)
- <<-CODE
- @#{attribute} ||= #{attr_fetcher(attribute)}
CODE
end
end
end