Skip to content

Commit

Permalink
Added support for page without host class to host class without attri…
Browse files Browse the repository at this point in the history
…bute_names method
  • Loading branch information
Bert Hajee authored and Bert Hajee committed Jun 14, 2013
1 parent 4301e5c commit 8f782ca
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/page_record/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ class PageRecord

def self.inherited(base)
base.class_eval do
@base_name = base.to_s.gsub('Page', '')
@type = @base_name.underscore
@host_class = @base_name.constantize
@attributes = @host_class.attribute_names.clone
@attributes.delete('id') # id is a special case attribute
set_type_name(base)
get_attribute_names
end
define_class_methods(base)
define_instance_methods(base)
end


class << self
attr_accessor :type
end
Expand All @@ -36,6 +34,21 @@ def self.attributes(new_attributes)

private

def self.set_type_name(base)
@base_name = base.to_s.gsub('Page', '')
@type = @base_name.underscore
end

def self.get_attribute_names
begin
@host_class = @base_name.constantize
@attributes = @host_class.attribute_names.clone
@attributes.delete('id') # id is a special case attribute
rescue NameError
@attributes = []
end
end


def self.define_accessor_methods(base)
base.instance_eval do
Expand Down

0 comments on commit 8f782ca

Please sign in to comment.