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



67
68
69
# File 'lib/active_scaffold/config/base.rb', line 67

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



69
70
71
72
# File 'lib/active_scaffold/config/base.rb', line 69

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.



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

def 
  @user_settings_key
end

Class Method Details

.inherited(subclass) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_scaffold/config/base.rb', line 22

def self.inherited(subclass)
  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



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

def crud_type
  self.class.crud_type
end

#label(model = nil) ⇒ Object



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

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

#model_idObject



47
48
49
# File 'lib/active_scaffold/config/base.rb', line 47

def model_id
  (core || self).model_id
end

#new_user_settings(storage, params) ⇒ Object



58
59
60
# File 'lib/active_scaffold/config/base.rb', line 58

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.



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

def user
  ActiveScaffold::Registry.[]
end