Skip to content

Commit

Permalink
Find schema by the field name (with some refractor)
Browse files Browse the repository at this point in the history
  • Loading branch information
pol committed Mar 23, 2012
1 parent 911eb2f commit 0bc27fa
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/yogo/collection/property.rb
Expand Up @@ -39,13 +39,24 @@ def versions
Yogo::Collection::Property.with_deleted.all(:original_uid=>self.id.to_s, :order=>[:deleted_at])
end

def self.by_field_name(fname)
get(self.field_name_to_uid(fname))
end

def self.field_name_to_uid(fname)
fname[6..-1].gsub('_','-')
end

def self.uid_to_field_name(uid)
'field_' + uid.to_s.gsub('-','_')
end

def field_name
self.to_s
end

def to_s
'field_' + self.id.to_s.gsub('-','_')
self.class.uid_to_field_name(self.id)
end

def as_json(opts=nil)
Expand Down

0 comments on commit 0bc27fa

Please sign in to comment.