Skip to content

Commit

Permalink
Use class_atribute instead of class_inheritable_accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
alsemyonov committed May 11, 2011
1 parent a3293a5 commit d07f2bd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
9 changes: 4 additions & 5 deletions lib/espresso.rb
@@ -1,13 +1,12 @@
$KCODE = 'u'
require 'active_support/core_ext/module'

module Espresso
autoload :Model, 'espresso/model'
autoload :View, 'espresso/view'
autoload :Model, 'espresso/model'
autoload :View, 'espresso/view'
autoload :Controller, 'espresso/controller'
autoload :Collection, 'espresso/collection'
autoload :Concern, 'espresso/concern'
autoload :Manage, 'espresso/manage'
autoload :Concern, 'espresso/concern'
autoload :Manage, 'espresso/manage'

BASE_MODULES = %w(model view controller)

Expand Down
4 changes: 2 additions & 2 deletions lib/espresso/model.rb
@@ -1,13 +1,13 @@
require 'espresso'
require 'active_support/core_ext/class/inheritable_attributes'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/string'

module Espresso
module Model
extend Espresso::Concern

included do
class_inheritable_accessor :name_field, :model_modifiers
class_attribute :name_field, :model_modifiers

self.name_field = :name
self.model_modifiers = []
Expand Down
28 changes: 6 additions & 22 deletions lib/espresso/model/inherited_resources.rb
@@ -1,21 +1,15 @@
require 'espresso/model'
require 'espresso/collection'
require 'inherited_resources'

module Espresso
module Model
included do
begin
if respond_to?(:scope) && respond_to?(:where) && respond_to?(:order)
scope :for_collection, where('1 = 1')
scope :for_feed, order('created_at DESC')
elsif respond_to?(:named_scope)
named_scope :for_collection, :conditions => '1 = 1'
named_scope :for_feed, :order => 'created_at DESC'
else
extend DummyScopes
end
rescue
extend DummyScopes
alias for_collection scoped
if respond_to?(:desc)
scope :for_feed, desc(:created_at)
else
scope :for_feed, order('created_at DESC')
end
end

Expand All @@ -27,15 +21,5 @@ def espresso_collection(options = {})
Espresso::Collection.new(self.for_collection, options)
end
end

module DummyScopes
def for_collection
self
end

def for_feed
self
end
end
end
end

0 comments on commit d07f2bd

Please sign in to comment.