Sha256: 3b68131a8989603e15f3e8139172374d45cd7402dd2a7651f24c2e76d7684f44

Contents?: true

Size: 411 Bytes

Versions: 7

Compression:

Stored size: 411 Bytes

Contents

module PR
  class BuildFromModel

    def self.[] klass, model
      new(PR::FieldRegistry[klass], klass.new).build_from model
    end

    def initialize registry, form
      @registry, @form = registry, form
    end

    def build_from model
      @registry.fields.each do |field|
        @form.send("__#{field}").populate model.send(field) if model.respond_to? field
      end
      @form
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pr-1.0.0 lib/pr/build_from_model.rb
pr-0.0.7 lib/pr/build_from_model.rb
pr-0.0.6 lib/pr/build_from_model.rb
pr-0.0.5 lib/pr/build_from_model.rb
pr-0.0.4 lib/pr/build_from_model.rb
pr-0.0.3 lib/pr/build_from_model.rb
pr-0.0.2 lib/pr/build_from_model.rb