Module: SelectableAttrRails

Defined in:
lib/selectable_attr_rails.rb,
lib/selectable_attr_rails/helpers.rb,
lib/selectable_attr_rails/version.rb,
lib/selectable_attr_rails/db_loadable.rb,
lib/selectable_attr_rails/validatable.rb,
lib/selectable_attr_rails/validatable/base.rb,
lib/selectable_attr_rails/validatable/enum.rb

Defined Under Namespace

Modules: DbLoadable, Helpers, Validatable

Constant Summary collapse

VERSION =
'0.0.3'

Class Method Summary collapse

Class Method Details

.add_features_to_action_viewObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/selectable_attr_rails.rb', line 29

def add_features_to_action_view
  ActionView::Base.module_eval do
    include ::SelectableAttrRails::Helpers::SelectHelper::Base
    include ::SelectableAttrRails::Helpers::CheckBoxGroupHelper::Base
    include ::SelectableAttrRails::Helpers::RadioButtonGroupHelper::Base
  end
  ActionView::Helpers::FormBuilder.module_eval do
    include ::SelectableAttrRails::Helpers::SelectHelper::FormBuilder
    include ::SelectableAttrRails::Helpers::CheckBoxGroupHelper::FormBuilder
    include ::SelectableAttrRails::Helpers::RadioButtonGroupHelper::FormBuilder
  end
  logger.debug("#{self.name}.add_features_to_action_view")
end

.add_features_to_active_recordObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/selectable_attr_rails.rb', line 17

def add_features_to_active_record
  ActiveRecord::Base.module_eval do
    include ::SelectableAttr::Base
    include ::SelectableAttrRails::Validatable::Base
  end
  SelectableAttr::Enum.module_eval do
    include ::SelectableAttrRails::DbLoadable
    include ::SelectableAttrRails::Validatable::Enum
  end
  logger.debug("#{self.name}.add_features_to_active_record")
end

.add_features_to_railsObject



43
44
45
46
# File 'lib/selectable_attr_rails.rb', line 43

def add_features_to_rails
  add_features_to_active_record
  add_features_to_action_view
end

.loggerObject



10
11
12
# File 'lib/selectable_attr_rails.rb', line 10

def logger
  @logger ||= Logger.new(STDERR)
end

.logger=(value) ⇒ Object



13
14
15
# File 'lib/selectable_attr_rails.rb', line 13

def logger=(value)
  @logger = value
end

.setupObject



48
49
50
51
52
53
# File 'lib/selectable_attr_rails.rb', line 48

def setup
  logger = defined?(Rails) ? Rails.logger : ActiveRecord::Base.logger
  self.logger = logger
  SelectableAttr.logger = logger if SelectableAttr.respond_to?(:logger=) # since 0.3.11
  add_features_to_rails
end