Class: RbsActivesupport::AttributeAccessor

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_activesupport/attribute_accessor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ AttributeAccessor

Returns a new instance of AttributeAccessor.



10
11
12
13
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 10

def initialize(name, options) #: void
  @name = name
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

: Symbol



5
6
7
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 5

def name
  @name
end

#optionsObject (readonly)

: Hash[untyped, untyped]



6
7
8
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 6

def options
  @options
end

Instance Method Details

#default?Boolean

: boolish

Returns:

  • (Boolean)


47
48
49
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 47

def default? #: boolish
  options.fetch(:default, nil)
end

#default_typeObject

: String



51
52
53
54
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 51

def default_type #: String
  default = options.fetch(:default, nil)
  RbsActivesupport::Types.guess_type(default)
end

#included?Boolean

: bool

Returns:

  • (Boolean)


64
65
66
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 64

def included? #: bool
  options.fetch(:included, false)
end

#instance_accessor?Boolean

: bool

Returns:

  • (Boolean)


35
36
37
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 35

def instance_accessor? #: bool
  options.fetch(:instance_accessor, true)
end

#instance_reader?Boolean

: bool

Returns:

  • (Boolean)


39
40
41
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 39

def instance_reader? #: bool
  options.fetch(:instance_reader, instance_accessor?)
end

#instance_writer?Boolean

: bool

Returns:

  • (Boolean)


43
44
45
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 43

def instance_writer? #: bool
  options.fetch(:instance_writer, instance_accessor?)
end

#private?Boolean

: bool

Returns:

  • (Boolean)


60
61
62
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 60

def private? #: bool
  options.fetch(:private, false)
end

#public?Boolean

: bool

Returns:

  • (Boolean)


56
57
58
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 56

def public? #: bool
  !private?
end

#singleton_reader?Boolean

: bool

Returns:

  • (Boolean)


27
28
29
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 27

def singleton_reader? #: bool
  options.fetch(:singleton_reader, true)
end

#singleton_writer?Boolean

: bool

Returns:

  • (Boolean)


31
32
33
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 31

def singleton_writer? #: bool
  options.fetch(:singleton_writer, true)
end

#typeObject

: String



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 15

def type #: String
  # @type var trailing_comment: String?
  trailing_comment = options[:trailing_comment]
  if trailing_comment&.start_with?("#:")
    trailing_comment[2..].strip
  elsif default?
    default_type
  else
    "untyped"
  end
end