Permalink
Browse files

Remove unused code; use delegator

  • Loading branch information...
1 parent c6865d0 commit 6a93cdf5a6561e7c16e22fc2b88ae50f65bded8f @pfleidi committed Nov 28, 2013
Showing with 4 additions and 50 deletions.
  1. +4 −50 lib/mlk/model.rb
View
@@ -6,6 +6,9 @@ module Mlk
class Model
include Scrivener::Validations
+ extend SingleForwardable
+
+ def_delegators :all, :first, :find, :find_match
class << self
attr_accessor :storage_engine
@@ -28,24 +31,10 @@ def self.default_sort_by
:name
end
- def [](name)
+ def self.[](name)
all.first(:name => name)
end
- # convenience wrappers around all()
-
- def self.first(filters = { })
- all.first(filters)
- end
-
- def self.find(filters)
- all.find(filters)
- end
-
- def self.find_match(filters)
- all.find_match(filters)
- end
-
def self.all
results = storage.all.map do |path, raw_document|
document = Document.new(raw_document)
@@ -102,41 +91,6 @@ def self.to_reference
self.name.downcase
end
- # Inheriting values for methods from other models (mostly connected by belongs_to)
-
- @@inheriting_methods = {}
-
- def self.inherits_from(parent_method, *args)
- args.each do |method_name|
- @@inheriting_methods[method_name] = parent_method
- end
- end
-
- def self.inheriting_for_method(name)
- if @@inheriting_methods.keys.include? name
- parent_method = @@inheriting_methods[name]
- @@inheriting_methods.delete(name)
- overwrite_inheriting_method(name, parent_method)
- end
- end
-
- def self.method_added(name)
- inheriting_for_method(name)
- end
-
- def self.overwrite_inheriting_method(name, parent_method)
- original_method_name = :"#{ name }_non_inheriting"
- alias_method original_method_name, name
-
- define_method(name) do
- if eval "#{ original_method_name }.nil?"
- eval "#{ parent_method }.#{ name }"
- else
- eval "#{ original_method_name }"
- end
- end
- end
-
attr_reader :document, :content, :data
attribute :name

0 comments on commit 6a93cdf

Please sign in to comment.