Sha256: d8b0b3c3dfef87f595a3b457f0267858c65c6b207d0bff0f104541d820224496

Contents?: true

Size: 889 Bytes

Versions: 9

Compression:

Stored size: 889 Bytes

Contents

module Extras
  module BookPresentation
    # A setter that creates an author on the fly
    def author_first_name_setter
      lambda do |r,v|

        data_adapter = Netzke::Basepack::DataAdapters::AbstractAdapter.adapter_class(Author).new(Author)
        # cast v to integer, if possible
        v = v.to_i if v.kind_of?(String) && v.match(/[[:digit:]]+/)
        if v.is_a?(Integer)
          r.author = data_adapter.find_record(v)
        else
          author = data_adapter.new_record(:first_name => v)
          # Sequel doesn't know of save!
          author.respond_to?(:save!) ? author.save! : author.save(:raise_on_save_failure => true)
          r.author = author
        end
      end
    end

    # A getter that returns "YES" if exemplars are more than 3, "NO" otherwise
    def in_abundance_getter
      lambda {|r| r.exemplars.to_i > 3 ? "YES" : "NO"}
    end

  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
netzke-basepack-0.8.4 test/basepack_test_app/app/components/extras/book_presentation.rb
netzke-basepack-0.8.3 test/basepack_test_app/app/components/extras/book_presentation.rb
netzke-basepack-0.8.2 test/basepack_test_app/app/components/extras/book_presentation.rb
netzke-basepack-0.8.1 test/basepack_test_app/app/components/extras/book_presentation.rb
netzke-basepack-0.8.0 test/basepack_test_app/app/components/extras/book_presentation.rb
netzke-basepack-0.7.7 test/basepack_test_app/app/components/extras/book_presentation.rb
netzke-basepack-zh-0.7.6 test/basepack_test_app/app/components/extras/book_presentation.rb
netzke-basepack-0.7.6 test/basepack_test_app/app/components/extras/book_presentation.rb
netzke-basepack-0.7.5 test/basepack_test_app/app/components/extras/book_presentation.rb