Sha256: 23540c6d7b1b8c8f4e64413bb99bd78856a6f12dd662ae9bcf07d2a0b1f2f43f

Contents?: true

Size: 433 Bytes

Versions: 12

Compression:

Stored size: 433 Bytes

Contents

module HumanAttributes
  class MethodBuilder
    include HumanAttributes::Config

    attr_reader :model_class

    def initialize(model_class)
      @model_class = model_class
    end

    def build(formatter)
      model_class.send(:define_method, formatter.method_name) do
        value = send(formatter.attribute) || formatter.default
        formatter.apply(self, value)
      end

      formatter.method_name
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
human_attributes-1.1.0 lib/human_attributes/method_builder.rb
human_attributes-1.0.0 lib/human_attributes/method_builder.rb
human_attributes-0.7.1 lib/human_attributes/method_builder.rb
human_attributes-0.7.0 lib/human_attributes/method_builder.rb
human_attributes-0.6.0 lib/human_attributes/method_builder.rb
human_attributes-0.5.0 lib/human_attributes/method_builder.rb
human_attributes-0.4.0 lib/human_attributes/method_builder.rb
human_attributes-0.3.1 lib/human_attributes/method_builder.rb
human_attributes-0.3.0 lib/human_attributes/method_builder.rb
human_attributes-0.2.0 lib/human_attributes/method_builder.rb
human_attributes-0.1.1 lib/human_attributes/method_builder.rb
human_attributes-0.1.0 lib/human_attributes/method_builder.rb