diff --git a/lib/simple_form_object.rb b/lib/simple_form_object.rb index 54eea04..e6958a8 100644 --- a/lib/simple_form_object.rb +++ b/lib/simple_form_object.rb @@ -1,4 +1,5 @@ -require "simple_form_object/version" +require_relative "simple_form_object/attribute" +require_relative "simple_form_object/version" require "active_model" require "active_support" @@ -45,35 +46,4 @@ def attributes end attribs end - - class Attribute - def initialize(name, type = nil, options) - @name = name - @type = type || :string - @options = options - - extract_options - end - - attr_accessor :name, :type, :options - - def fake_column - self - end - - def apply_default_to(form) - if form.send(@name).nil? - form.send("#{@name}=", @default) if @apply_default - end - end - - private - - def extract_options - @apply_default = true - @default = options.fetch(:default) { @apply_default = false; nil } - @skip_validations = options.fetch(:skip_validations, false) - end - end - end diff --git a/lib/simple_form_object/attribute.rb b/lib/simple_form_object/attribute.rb new file mode 100644 index 0000000..022d1e5 --- /dev/null +++ b/lib/simple_form_object/attribute.rb @@ -0,0 +1,31 @@ +module SimpleFormObject + class Attribute + def initialize(name, type = nil, options) + @name = name + @type = type || :string + @options = options + + extract_options + end + + attr_accessor :name, :type, :options + + def fake_column + self + end + + def apply_default_to(form) + if form.send(@name).nil? + form.send("#{@name}=", @default) if @apply_default + end + end + + private + + def extract_options + @apply_default = true + @default = options.fetch(:default) { @apply_default = false; nil } + @skip_validations = options.fetch(:skip_validations, false) + end + end +end