Class: ActiveScaffold::Config::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveScaffold::Configurable
Includes:
ActiveScaffold::Configurable
Defined in:
lib/active_scaffold/config/base.rb

Defined Under Namespace

Classes: UserSettings

Constant Summary collapse

NO_FORMATS =
[].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveScaffold::Configurable

configure, method_missing, respond_to_missing?

Constructor Details

#initialize(core_config) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
# File 'lib/active_scaffold/config/base.rb', line 7

def initialize(core_config)
  @core = core_config
  @action_group = self.class.action_group.clone if self.class.action_group

  # start with the ActionLink defined globally
  @link = self.class.link.clone if self.class.respond_to?(:link) && self.class.link
  setup_user_setting_key
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveScaffold::Configurable

Instance Attribute Details

#action_groupObject

action_group this action should belong to



52
53
54
# File 'lib/active_scaffold/config/base.rb', line 52

def action_group
  @action_group
end

#coreObject (readonly)

Returns the value of attribute core.



20
21
22
# File 'lib/active_scaffold/config/base.rb', line 20

def core
  @core
end

#formatsObject



54
55
56
57
# File 'lib/active_scaffold/config/base.rb', line 54

def formats
  return @formats || NO_FORMATS if frozen?
  @formats ||= NO_FORMATS.dup
end

#user_settings_keyObject (readonly)

Returns the value of attribute user_settings_key.



36
37
38
# File 'lib/active_scaffold/config/base.rb', line 36

def 
  @user_settings_key
end

Class Method Details

.inherited(subclass) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/active_scaffold/config/base.rb', line 141

def self.inherited(subclass)
  subclass.const_set 'UserSettings', Class.new(subclass.superclass::UserSettings)
  class << subclass
    # the crud type of the action. possible values are :create, :read, :update, :delete, and nil.
    # this is not a setting for the developer. it's self-description for the actions.
    attr_reader :crud_type

    protected

    def crud_type=(val)
      raise ArgumentError, "unknown CRUD type #{val}" unless %i[create read update delete].include?(val.to_sym)
      @crud_type = val.to_sym
    end
  end
end

Instance Method Details

#crud_typeObject

delegate



23
24
25
# File 'lib/active_scaffold/config/base.rb', line 23

def crud_type
  self.class.crud_type
end

#label(model = nil) ⇒ Object



27
28
29
30
# File 'lib/active_scaffold/config/base.rb', line 27

def label(model = nil)
  model ||= @core.label(:count => 1)
  @label.nil? ? model : as_(@label, :model => model)
end

#model_idObject



32
33
34
# File 'lib/active_scaffold/config/base.rb', line 32

def model_id
  (core || self).model_id
end

#new_user_settings(storage, params) ⇒ Object



43
44
45
# File 'lib/active_scaffold/config/base.rb', line 43

def (storage, params)
  ActiveScaffold::Registry.[] = self.class::UserSettings.new(self, storage, params)
end

#setup_user_setting_keyObject



16
17
18
# File 'lib/active_scaffold/config/base.rb', line 16

def setup_user_setting_key
  @user_settings_key = :"#{model_id}_#{self.class.name.underscore}"
end

#userObject

the user property gets set to the instantiation of the local UserSettings class during the automatic instantiation of this class.



39
40
41
# File 'lib/active_scaffold/config/base.rb', line 39

def user
  ActiveScaffold::Registry.[]
end