Module: IfStatement
- Defined in:
- lib/if_statement.rb,
lib/if_statement/railtie.rb,
lib/if_statement/version.rb,
lib/if_statement/features.rb
Defined Under Namespace
Modules: Features Classes: Railtie
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
-
.define(identifier, value = nil, &block) ⇒ Object
define a specific feature give a boolean value, or a block.
- .features ⇒ Object
-
.read(identifier) ⇒ Object
reads the current value of identifier.
-
.setup(&block) ⇒ Object
set up a bunch of features.
Instance Method Summary collapse
Class Method Details
.define(identifier, value = nil, &block) ⇒ Object
define a specific feature
give a boolean value, or a block
24 25 26 27 28 29 30 31 |
# File 'lib/if_statement.rb', line 24 def define identifier, value=nil, &block identifier = identifier.to_sym if block features[identifier] = block else features[identifier] = !!value end end |
.features ⇒ Object
39 40 41 |
# File 'lib/if_statement.rb', line 39 def features @features ||= {} end |
.read(identifier) ⇒ Object
reads the current value of identifier
34 35 36 37 |
# File 'lib/if_statement.rb', line 34 def read identifier value = features[identifier] value.nil? ? false : value end |
.setup(&block) ⇒ Object
set up a bunch of features
usage
IfStatement.setup do
set :messaging, true
set(:admin) { current_user.admin? }
end
14 15 16 17 18 19 20 |
# File 'lib/if_statement.rb', line 14 def setup &block def set identifier, value=nil, &block define identifier, value, &block end class_eval(&block) end |
Instance Method Details
#set(identifier, value = nil, &block) ⇒ Object
15 16 17 |
# File 'lib/if_statement.rb', line 15 def set identifier, value=nil, &block define identifier, value, &block end |