Sha256: 7cec5263ccbaff9d0353452276a2b3e59b6496d1c069cfba923ffec87a8f0a14

Contents?: true

Size: 1021 Bytes

Versions: 25

Compression:

Stored size: 1021 Bytes

Contents

module DynamicScaffold
  module List
    class Item
      attr_reader :classnames, :html_attributes

      def initialize(config, *args, block)
        @config = config
        @html_attributes = args.extract_options!
        @classnames = @html_attributes.delete(:class)
        @attribute_name = args[0]
        @block = block
        @show_only = nil
      end

      def show_only(&block)
        @show_only = block
        self
      end

      def show?(view, record)
        return true if @show_only.nil?

        view.instance_exec(record, &@show_only)
      end

      def value(view, record)
        if @block
          view.instance_exec(record, @attribute_name, &@block)
        else
          record.public_send(@attribute_name)
        end
      end

      def label(label = nil)
        if label
          @label = label
          self
        elsif @label
          @label
        elsif @attribute_name
          @config.model.human_attribute_name @attribute_name
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
dynamic_scaffold-1.12.2 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.12.1 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.12.0 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.11.0 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.10.0 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.9.0 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.8.1 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.8.0 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.7.1 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.7.0 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.6.0 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.5.0 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.4.3 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.4.2 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.4.1 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.4.0 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.3.0 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.2.2 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.2.1 lib/dynamic_scaffold/list/item.rb
dynamic_scaffold-1.2.0 lib/dynamic_scaffold/list/item.rb