Module: Ark::Record
- Defined in:
- lib/ark/record.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Ignore this for now I’ve been dithering back and forth on the API all night The way you use this is: class Host; include Ark::Record; end As long as there’s a valid schema for ‘host`, you’ll have a workable class.
Class Method Details
.included(base) ⇒ Object
Ignore this for now I’ve been dithering back and forth on the API all night The way you use this is: class Host; include Ark::Record; end As long as there’s a valid schema for ‘host`, you’ll have a workable class
However, I think there’s a use case for combo record+schema creation..
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ark/record.rb', line 12 def self.included(base) db = Ark::Repo.db || Ark::Repo.connect base.extend ClassMethods klass = base.to_s.gsub(/^.*::/, '').downcase begin record = db.get("_schema/#{klass}.json") raise Ark::SchemaNotFoundError if record.nil? data = ::JSON.parse(record) end base.class_eval do attr_accessor *data['attributes'] attr_reader :schema, :basepath, :errors, :record_type, :db define_method("schema") { instance_variable_set("@schema", data) } define_method("basepath") { instance_variable_set("@basepath", "_objects") } define_method("record_type") { instance_variable_set("@record_type", data['id']) } define_method("db") { instance_variable_set("@db", db) } end end |