Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added an extra :mixins option to jsonmodel to allow the caller to mix…

… in their own modules.

Modified the frontend to use this new feature to create some methods required
to make form_helper play nicely with arrays.
  • Loading branch information...
commit c65f357517d752e861a64ec9d4045d74177a1c51 1 parent 60e60ba
@marktriggs marktriggs authored
Showing with 32 additions and 2 deletions.
  1. +9 −2 common/jsonmodel.rb
  2. +23 −0 frontend/config/initializers/json_object.rb
View
11 common/jsonmodel.rb
@@ -628,15 +628,22 @@ def self.keys_as_strings(hash)
require_relative 'jsonmodel_client'
include JSONModel::Client
end
- end
-
+ end
cls.define_accessors(schema['properties'].keys)
@@types[cls] = type
@@schema[cls] = schema
@@models[type] = cls
+
+ cls.instance_eval do
+ (@@init_args[:mixins] or []).each do |mixin|
+ include(mixin)
+ end
+ end
+
+
end
View
23 frontend/config/initializers/json_object.rb
@@ -1,6 +1,29 @@
require "jsonmodel"
+module RailsFormMixin
+
+ def self.included(base)
+ # For any array types in this schema, define a setter that will trigger
+ # form_helper to do what we want.
+ base.schema['properties'].each do |name, property|
+ if property['type'].downcase == 'array'
+ base.instance_eval do
+ define_method "#{name}_attributes=" do
+ end
+ end
+ end
+ end
+ end
+
+
+ def persisted?
+ false
+ end
+end
+
+
JSONModel::init(:client_mode => true,
+ :mixins => [RailsFormMixin],
:url => ArchivesSpace::Application.config.backend_url)
JSONModel::add_error_handler do |error|
Please sign in to comment.
Something went wrong with that request. Please try again.