lib/jaysus/base.rb in jaysus-0.1.1 vs lib/jaysus/base.rb in jaysus-0.1.2
- old
+ new
@@ -53,11 +53,11 @@
end
def self.decode(id, &block)
ActiveSupport::JSON.decode(
yield
- )[self.model_name.singular]
+ )[self.store_file_dir_name.singularize]
end
def self.model_base
"#{model_name}::Base".constantize
end
@@ -69,13 +69,12 @@
def self.remote_base
"#{model_name}::Remote".constantize
end
def self.model_name
- parts = super.split('::')
- name_part = parts[parts.length-2]
- ActiveModel::Name.new(name_part.constantize)
+ parts = super.reverse.split('::',2).reverse.map { |p| p.reverse }
+ ActiveModel::Name.new(parts.first.constantize)
end
def self.plural_name
model_name.plural
end
@@ -93,11 +92,23 @@
dir = Local.store_dir.join(store_file_dir_name)
dir.mkpath unless dir.exist?
dir
end
+ def self.object_name
+ self.model_name.split('::').last
+ end
+
+ def self.plural_object_name
+ self.object_name.underscore.pluralize
+ end
+
+ def self.singular_object_name
+ self.object_name.underscore.singularize
+ end
+
def self.store_file_dir_name
- self.model_name.plural
+ self.plural_object_name
end
def self.method_missing(method, *args)
if method.to_s.match(/^find_by/)
attrs = method.to_s.gsub(/^find_by_/, '').split('_and_')
\ No newline at end of file