Module: Mist::Configuration

Included in:
Mist
Defined in:
lib/mist/configuration.rb

Defined Under Namespace

Classes: Author

Instance Method Summary collapse

Instance Method Details

#authorObject



32
33
34
# File 'lib/mist/configuration.rb', line 32

def author
  @author ||= Mist::Configuration::Author.new
end

#authorizationsObject



20
21
22
# File 'lib/mist/configuration.rb', line 20

def authorizations
  @authorizations ||= {}.with_indifferent_access
end

#authorize(*types, &block) ⇒ Object

Register a block to be invoked whenever Mist needs to know if a user is allowed to perform some action, such as :create_post, :edit_post, :view_post, :destroy_post, or :all.

Mist.authorize { |controller| ... }               # invoke for any action not otherwise registered
Mist.authorize(:all) { |controller| ... }         # same as above
Mist.authorize(:create_post) { |controller| ... } # use this block only for :create_post

By default, all authorization requests will return false (denied).

Raises:

  • (ArgumentError)


54
55
56
57
58
# File 'lib/mist/configuration.rb', line 54

def authorize(*types, &block)
  raise ArgumentError, "Expected a block which will be evaluated at runtime" unless block_given?
  types.push :all if types.empty?
  types.each { |type| authorizations[type] = block }
end

#authorized?(action, *args) ⇒ Boolean

Invokes the blocks registered by Mist::Configuration#authorize to see if the specified action is authorized. Passes *args into the block.

Returns:

  • (Boolean)


62
63
64
65
66
67
# File 'lib/mist/configuration.rb', line 62

def authorized?(action, *args)
  if authorizations.key?(action) then authorizations[action].call *args
  elsif authorizations.key?(:all) then authorizations[:all].call *args
  else nil
  end
end

#commit_meta_dataObject



24
25
26
# File 'lib/mist/configuration.rb', line 24

def 
  @commit_meta_data = true if @commit_meta_data.nil?
end

#commit_meta_data=(a) ⇒ Object



28
29
30
# File 'lib/mist/configuration.rb', line 28

def commit_meta_data=(a)
  @commit_meta_data = a
end

#default_repository_locationObject



12
13
14
# File 'lib/mist/configuration.rb', line 12

def default_repository_location
  Rails.root.join("db/mist.repo.#{Rails.env}")
end

#repository_locationObject



4
5
6
# File 'lib/mist/configuration.rb', line 4

def repository_location
  @respository_location ||= default_repository_location
end

#repository_location=(dir) ⇒ Object



8
9
10
# File 'lib/mist/configuration.rb', line 8

def repository_location=(dir)
  @respository_location = dir
end

#reset_authorizations!Object



16
17
18
# File 'lib/mist/configuration.rb', line 16

def reset_authorizations!
  authorizations.clear
end

#titleObject



40
41
42
# File 'lib/mist/configuration.rb', line 40

def title
  @title ||= "Blog Title"
end

#title=(title) ⇒ Object



36
37
38
# File 'lib/mist/configuration.rb', line 36

def title=(title)
  @title = title
end